• 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

java.net.SocketException: Socket is closed

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic