Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic