I am using old school java.net.Socket
My client connects to server and does:
BufferedReader in =
new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String fromServer = in.readLine();
It hangs at in.readLine().
My server accepts a connection from the client and does:
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
out.print("Hello client\n");
My expectation would be that as soon as out.print(“Hello client\n”); is invoked, the client should stop blocking and continue on.
What are my doing wrong?
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
BufferedReader in =
new BufferedReader( new InputStreamReader(clientSocket.getInputStream()));
String fromServer = in.readLine();
I guess you are not calling
out.flush();See PrintWriter.flushFrom Javadoc
So
Autoflushwill not work forprintyou will need to callflush()mannually