• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.net.SocketException: Socket is closed  RSS feed

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

I am running some code and I get this exception:

I/O Socket is closed
java.net.SocketException: Socket is closed
at java.net.Socket.getOutputStream(Socket.java:808)
at iitm.donlab.mpp.transport.IsoClient.sendMessage(IsoClient.java:282)
at iitm.donlab.mpp.manager.IsoMsgHandler.performActionPush(IsoMsgHandler.java:568)
at iitm.donlab.mpp.transport.IsoClient$ProcessorClient.run(IsoClient.java:175)
at java.lang.Thread.run(Thread.java:619)
The snippet of code is as follows:

I get sock.isConnected() as true and sock.inInputShutdown() and sock.isOutputShutdown() both as false. sick.isBound() is also true.

Could you please tell me the reasons I could get the error at this line "isoMsg.write(sock.getOutputStream(), 2);" even when the socket is connected and the streams are not shut down.

 
Rob Spoor
Sheriff
Posts: 21050
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
isInputShutdown() will always return false until shutdownInput() has been called. This does not occur when the socket is closed, as far as I could see. Likewise for isOutputShutdown().
isBound() and isConnected() return whether or not sometime in the past the socket was bound / connected. Once they have returned true they will never again return false. In that manner the names should have been hasBeenBound() and hasBeenConnected().

What does isClosed() return?
 
mayank gupta
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been able to solve the problem.

I was closing the socket in a finally block which i had overlooked earlier.
Thank you for the information on the methods.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!