TCP连接建立
我正在尝试通过java程序连接到远程主机:
socket = new java.net.Socket(host,port);
我收到以下异常:
java.net.ConnectException: Connection refused: connect
跟踪我的计算机和远程主机之间的IP数据包,我看到我的计算机发送了三次SYN数据包,并收到了[RST,ACK]包三遍。
为什么我的计算机只建立了一个连接,却发送了三个 SYN 数据包?
是由于操作系统的 TCP/IP 堆栈造成的吗?
或者是由于 Java 的 java.net.Socket 实现 类?
I am trying to connect to a remote host via the java program:
socket = new java.net.Socket(host,port);
I am getting the following exception:
java.net.ConnectException: Connection refused: connect
Tracing IP packets between my computer and the remote host, I see that my computer sent SYN packets three times, and received [RST,ACK] packets three times .
Why does my computer send three SYN packets despite only one connection establishent?
Is it due to the TCP/IP stack of the OS?
Or is it due to Java's implementation of java.net.Socket class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SYN 的重传可能是为了遵守 RFC793 :
重试 SYN 是有道理的,因为无论出于何种原因,ACK 都可能丢失。重传的次数和超时取决于 TCP 实现而不是 Java。
The retransmission of the SYN is probably done to comply with RFC793 :
It makes sense that the SYN would be retried since it's possible that for whatever reason the ACK just got lost. The number of times that that's retransmitted and the timeout would depend on the TCP implementation not Java.