打开的插座和连接的插座有什么区别? [英] Whats the difference between a socket which is open and a socket which is connected?
问题描述
Java Socket
类有两种方法 isClosed
和 isConnected
分别检查插座是否已关闭或已连接。我想知道一个只打开的TCP套接字和一个打开并连接的TCP套接字有什么区别,这与UDP有什么区别。
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.
推荐答案
简单地说, open 的 Socket
是一个等待连接或成功的套接字连接另一个 Socket
。当套接字关闭时,意味着此套接字不再可用于连接,并且它的资源已经被释放。连接的 Socket
,这意味着套接字连接到另一个 Socket
。
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
.
所以套接字
可以..
- 同时打开并连接。
- 打开并且没有同时连接。
- 没有连接关闭时。
更新
来自@Bryan
显然,TCP套接字有半封闭或半开状态;哪个用法(今天)与其原始含义不同。有关此链接的更多信息。
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.
这篇关于打开的插座和连接的插座有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!