• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception while writing to outjava.net.SocketException: Socket closed  RSS feed

 
vidya archana
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i tried to parse an xml file, send through a socket connection, i am getting an excepton :
"Exception while writing to outjava.net.SocketException: Socket closed"..
But we are able to parse the full file.
what could be the reason?
 
Vijayakumar Arya
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
The exception clearly says that the socket is getting closed, it could be because you are closing the socket at the receiving end before reading the entire file.
For instance, you assume that you are writing about 1000 bytes of data into the socket. In the receiving end you might be closing the socket connection before reading 1000 bytes (0-999 bytes).
To prevent, either use readfully() method of the input stream to read the data from the socket or loop till the method read() of input stream returns -1.
Hope this helps
---------------
Vijay.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!