Hello =) I ask you to explain to me the reason for the occurrence of such a problem. Here is a small client-server application code.
Customer:
Socket socket = new Socket("localhost", 2001); ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(socket.getOutputStream())); System.out.println("step1"); ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(socket.getInputStream())); System.out.println("step2"); in.close(); out.close();
Server:
ServerSocket ss = new ServerSocket(2001); Socket socket = ss.accept(); ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(socket.getOutputStream())); System.out.println("step1"); ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(socket.getInputStream())); System.out.println("step2"); in.close(); out.close();
At startup, both consoles display only step1 and "hang".
If you do not use a buffer, i.e. don't "wrap" the received streams from the socket into the Buffered..Stream, then everything works as expected.
What is my problem? :)