for my exercise i need to make a TCP connection where client sends couple of names, and server sends this names in uppercase, and cliend displays this uppercase names.
When i make a one way connection to server to display name its ok, but when i want to send this names back to client, my programm is waiting for somethin, i dont understand why,
could you suggest me something tp make it work?
when is says client connected, program is stuck...
The first one is that the server has no way of knowing when the client is finished providing data. You need to have the client and sent some kind of sentinel value to the server to indicate that it is done (empty line, single period, etc.), so that the server can stop collecting data, and then do the processing.
Another issue is that your client never actually connects to the server. You are missing the call to Socket#connect.
Thirdly, the client expects the payload returned by the server to be a single line, but if the client provide multiple lines of data (as you have in your example code), the client will close the socket before reading all of the content provided by the server.
Ron McLeod wrote:One other comment .. I would have probably used PrintWriter and BufferedReader rather than Formatter and Scanner since you are not really using any of the features that those classes bring.
Yes i see on many videos on youtube using these two objects; but in our school they give us, that we may better use this Scanner and Formatter.
I'm thinking about a new battle cry. Maybe "Not in the face! Not in the face!" Any thoughts tiny ad?