Whats the difference between a socket which is open and a socket which is connected?

后端 未结 2 1335
独厮守ぢ
独厮守ぢ 2020-12-19 00:22

The Java Socket class has two methods isClosed and isConnected to check whether the socket is closed or connected respectively. I want

2条回答
  •  春和景丽
    2020-12-19 01:02

    To put things simply, a Socket that is open is a socket that is either waiting for connection or has successfully connected with another Socket. When a socket has been closed, it means that this socket is no longer available for connection, and that it's resources has already been released. A Socket that is connected, well, it means that the socket is connected to another Socket.

    So a Socket can..

    • be open and connected at the same time.
    • be open and not connected at the same time.
    • not be connected when closed.

    UPDATE

    from @Bryan

    Apparently, there are half-closed or half-open states for TCP Sockets; which usage (today) is different from its original meaning. More on this link.

提交回复
热议问题