[Logo]
Forums Register Login
Error: java.net.SocketException: Connection reset
This error happens whenever a client connects to my server.
Here is my code:

Server:







Client:



Output:
Server:
Error: java.net.SocketException: Connection reset
Client:
<nothing>
Help appreiciated!
Me:
Hi,
You are closing the Socket in your client program as soon as you open it ,causing the Server side streams to close abruptly. Change your client code to write something to the stream .



This would cause the server to print the value and then throw the reset exception(since the client is terminated)
Also note that since you are using the readLine() at the server, you must terminate the string at the client side with a new line

a good java trail for starting client server programming http://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html
Hi,
You are closing the Socket in your client program as soon as you open it ,causing the Server side streams to close abruptly. Change your client code to write something to the stream .



This would cause the server to print the value and then throw the reset exception(since the client is terminated)
Also note that since you are using the readLine at the server, you must terminate the string at the client side with a new line

a good java trail for starting client server programming http://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html
See below below
See below
I found out the problem!
The code totally works!
I just didn't call the startServer(Socket server) method

Old code:


New code:

The problem is in your client program,you are not calling the startServer method (line 08). Another problem you would have is , on the client side you are using an writeBytes() which would not add a terminating new line ,whereas you are expecting
newline terminate string by using readLine() . to fix it you can append the new line manually before writing to the output stream (line 25 "+"\n" )


Since you are dealing with just strings, i think an alternative better way to handle it would be to just use a PrintWriter



I have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss


This thread has been viewed 34357 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jul 16, 2018 04:59:07.