• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Error: java.net.SocketException: Connection reset

 
Greenhorn
Posts: 28
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See below below
 
Heg Lachher
Greenhorn
Posts: 28
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See below
 
Heg Lachher
Greenhorn
Posts: 28
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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



 
reply
    Bookmark Topic Watch Topic
  • New Topic