Java Socket How do I tell when the connection is closed and how do I open it again

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jlparise
    New Member
    • Jan 2008
    • 9

    #1

    Java Socket How do I tell when the connection is closed and how do I open it again

    Hey everyone,

    I am really rusty on my Java socket programming and am having some confusing problems. I don't need the code debugged(even though it doesn't work). I'm not going to make you dig through all the abstraction layers and such.

    Anyways here is my issue. The application sends a request for data to the server and the server responds. However, the server then sends a TCP Fin message to close the connection which I can see through wire shark.

    How do I tell when the connection is closed and how do I open it again? Also, what do isClosed, isBound and isCOnnected do in the Java socket class.

    My program is crashing because I am trying to write to a closed socket(I think).


    However, I get the following weird scenario:

    isConnected True
    isBound True
    isClosed False

    This would seem to indicate the socket is still open, but when I write to the socket I get the following Exception:

    java.net.Socket Exception: Software caused connection abort: socket write error
    at java.net.Socket OutputStream.so cketWrite0(Nati ve Method)

    Can anyone explain what is going on?

    Thanks,

    Jon
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).

    This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.

    MODERATOR

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by jlparise
      Hey everyone,

      I am really rusty on my Java socket programming and am having some confusing problems. I don't need the code debugged(even though it doesn't work). I'm not going to make you dig through all the abstraction layers and such.

      Anyways here is my issue. The application sends a request for data to the server and the server responds. However, the server then sends a TCP Fin message to close the connection which I can see through wire shark.

      How do I tell when the connection is closed and how do I open it again? Also, what do isClosed, isBound and isCOnnected do in the Java socket class.

      My program is crashing because I am trying to write to a closed socket(I think).


      However, I get the following weird scenario:

      isConnected True
      isBound True
      isClosed False

      This would seem to indicate the socket is still open, but when I write to the socket I get the following Exception:

      java.net.Socket Exception: Software caused connection abort: socket write error
      at java.net.Socket OutputStream.so cketWrite0(Nati ve Method)

      Can anyone explain what is going on?

      Thanks,

      Jon
      You can read the specs for the Socket class to find out more about those methods.

      Comment

      Working...