The Java Socket class has two methods isClosed and isConnected to check whether the socket is closed or connected respectively. I wanted to know what’s the difference between a TCP socket which is only open and a TCP socket which is open and connected, and how is this different from UDP.
The Java Socket class has two methods isClosed and isConnected to check whether the
Share
To put things simply, a
Socketthat is open is a socket that is either waiting for connection or has successfully connected with anotherSocket. 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. ASocketthat is connected, well, it means that the socket is connected to anotherSocket.So a
Socketcan..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.