3 Replies Latest reply: Jan 7, 2004 11:58 AM by 807582 RSS

    How to close the Client Socket

    807582
      Hi All,

      I have a Client Socket Connected to Server. My Server is some Different Application (Not a Java Application). If the Server is Closed, I want my Client Application to be Closed.Can some help me out in doing so... Thank U Very much.

      Madan


        • 1. Re: How to close the Client Socket
          807582
          Your server should just close the sockets it has open from clients. If the client isn't reading the socket, it may not close, that's its problem.
          • 2. Re: How to close the Client Socket
            807582
            when you create a socket and the other end close the connection (or the connection is lost for some technical problem) an IOException is throw.

            you can close your application when this occurs.
            I noticed that the exception is thrown immediately when the other side closes the connection. If your server can't close the connection explicitly (i.e. it crashes) you could wait for a while before the exception is thrown. to prevend it you could ping the server every x seconds.
            when the server is off-line the IOException is thrown and you can close your application
            • 3. Re: How to close the Client Socket
              807582
              You have 2 conditions that indicate that the socket has been closed. The usual one is that a read method returns a length of -1. This occurs if the other end closes properly. The other is an exception on either read or write, this occurs if the other end crashes or you close the socket and then try to use it.