• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Error: java.net.SocketException: Connection reset  RSS feed

 
Greenhorn
Posts: 28
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
narendra darlanka
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Heg Lachher
Greenhorn
Posts: 28
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See below below
 
Heg Lachher
Greenhorn
Posts: 28
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See below
 
Heg Lachher
Greenhorn
Posts: 28
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found out the problem!
The code totally works!
I just didn't call the startServer(Socket server) method

Old code:


New code:
 
narendra darlanka
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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



  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!