• Post Reply Bookmark Topic Watch Topic
  • New Topic

SocketException  RSS feed

 
nii addy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have written a simple client server program to mimic the core processes of a bank i.e. withraw, deposit etc. The server can handle multiple clients, but when i close down one client window i get the following error.
****************************************************************
java.net.SocketException: Connection reset by peer: JVM_recv in socket input str
eam read
at java.net.SocketInputStream.socketRead(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:86)
at java.net.SocketInputStream.read(SocketInputStream.java:67)
at java.io.InputStreamReader.fill(InputStreamReader.java:173)
at java.io.InputStreamReader.read(InputStreamReader.java:249)
at java.io.BufferedReader.fill(BufferedReader.java:139)
at java.io.BufferedReader.readLine(BufferedReader.java:299)
at java.io.BufferedReader.readLine(BufferedReader.java:362)
at bank.ServerHandler.run(ServerHandler.java:47)
at java.lang.Thread.run(Thread.java:484)
**********************************************************
Can anyone tell me how to solve this problem please.
Thanks
 
Shubhrajit Chatterjee
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This occurs when a thread tries to write to a socket which has already been closed at the other end.
------------------
Shubhrajit :-)
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed. Having a client hanging up on you is a legitimate error condition and the resulting exception is something you'll simply have to catch and handle (clean up what needs cleaning up and otherwise ignore it is often sufficient).
On a completely different note, I suggest that ServerHandler should not extend Thread, but simply implement Runnable. That way, you can more easily fit a thread pool into your server later if need be.
- Peter
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!