• Post Reply Bookmark Topic Watch Topic
  • New Topic

I/o Error when getting outputstream

 
mayank gupta
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I get an IOException when I run my program. I am first opening a socket connection and then trying to do a . The exception occurs at this point.
It is twice that the executes this piece of code which creates a connection and calls the getOutputStream. The first time it executes fine, the second time i get an exception.
Before getting the output stream i check whether the socket is not null and it is connected. And even though the sock is not null and is connected but when it reaches the line getOutputStream, it throws an exception.


Can you please help me with the reasons why an IO excepton would occur when trying to get the output stream?
 
mayank gupta
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also get sock.isConnected() true and sock.isClosed() also as true.
 
mayank gupta
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got the solution, Had not closed the socket in the first acsess,
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All isXXX methods of Socket return true if that condition has ever been true. Once these properties are set to true they never become false anymore. So isConnected returns true if the socket is now or has ever been connected. Using isClosed, perhaps with isOutputShutdown and isInputShutdown, seems to be a better idea.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!