• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

I/o Error when getting outputstream

 
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,
 
Sheriff
Posts: 21997
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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.
 
Seriously? That's what you're going with? I prefer this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic