• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic