I have server and client. My server acepts all connections and returns to client string. But when I try to send more lines its crashed with
java.net.Soc
From the javadoc of getOutputStream() in Socket:
Closing the returned OutputStream will close the associated socket.
Also, closing a PrintWriter
(and all other Printers/Writers) close their underlying streams as well. So, you are closing your OutputStream
by closing the PrintWriter
(in hiMsg()
) and then trying to write to the socket, which was closed.
To fix the problem, don't close the PrintWriter
. Garbage collection will take care of it for you! But do close the socket when you are done with it.