After a ServerSocket accepts a connection to a client, can the ServerSocket start writing data to the client before the client sends a message? When I try to write to the client from the ServerSocket first, the client is blocking forever tyring to read it. However, if have the client send a message to the server first, the I/O streams between them work OK.
Asked
Active
Viewed 226 times
0
-
Sure, you can write to the server<>client socket as returned by accept() before the client sends anything. Servers often send 'welcome' banners upon connection and then ask for username. See EJP answer for likely problem. – Martin James Nov 01 '14 at 08:49
2 Answers
1
The ServerSocket
can neither read nor write, but the accepted Socket
can do both, in either order, or simultaneously.
Probably you are reading lines but not sending lines, or else not flushing a buffered output stream or writer.

user207421
- 305,947
- 44
- 307
- 483
1
Yes, you are correct that I meant getting the Socket from the accept() method.
My problem was very simple. The client was doing a readLine() method call but the server was not sending the "\n" character.

Michael Remijan
- 687
- 7
- 22