如果异常终止,如何重新连接最新的套接字? [英] How do I re-connect latest socket in the case of abnormal termination?

查看:168
本文介绍了如果异常终止,如何重新连接最新的套接字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在PC中使用VC ++中的MFC。

在我的TCP / IP套接字通信中,我的客户端套接字丢失了当它遇到一个严重的异常错误并且程序终止时。



接下来,客户端程序重启以使新的套接字连接到同一个服务器,有很多复位控制Wireshark屏幕上的消息和循环。



我无法理解消息的含义,所以让我告诉直接编码方法。



来源目的地港口号信息

----------------------------- -------------------------------------------------- -------------

服务器 - >客户3999-> 3224 [PSH,ACK] Seq = 101743 Ack = 11 Win = 5840 Len = 55

服务器 - >客户3999-> 3224 [PSH,ACK] Seq = 101798 Ack = 11 Win = 5840 Len = 51

客户 - >服务器3224-> 3999 [ACK] Seq = 11 Ack = 101849 Win = 62992 Len = 0



此时PC客户端因异常错误而终止并发送以下重置消息。



客户 - >服务器3224-> 3999 [RST,ACK] Seq = 11 Ack = 101849 Win = 0 Len = 0



接下来,客户端重新启动以创建新套接字(3361并尝试与同一服务器通信。



客户 - >服务器3361-> 3999 [SYN] Seq = 0 Win = 8192 Len = 0 MSS = 1460 WS = 256 SACK_PERM = 1



服务器 - >客户端3999-> 3361 [RST,ACK] Seq = 1 Ack = 1 Win = 0 Len = 0



客户端 - >服务器3361-> 3999 [TCP虚假重传] Seq = 0 Win = 8192 Len = 0 MSS = 1460 WS = 256 SACK_PERM = 1





服务器 - >客户端3999-> 3361 [RST,ACK] Seq = 1 Ack = 1 Win = 0 Len = 0



客户端 - >服务器3361-> 3999 [TCP虚假重传] Seq = 0 Win = 8192 Len = 0 MSS = 1460 SACK_PERM = 1



服务器 - >客户3999-> 3361 [RST,ACK] Seq = 1 Ack = 1 Win = 0 Len = 0



......





请告诉我这个案例的正确代码方法。



谢谢。



我尝试了什么:



超过1周,我浪费了我遇到这个问题的时间。

Hi,

I use MFC in VC++ in PC.
In my TCP/IP socket communication, my client socket is lost when it met a critical abnormal error and program terminated.

Next, the client program restart to make a new socket to connect to the same server, there are many reset control messages and looping in the Wireshark screen.

I cannot understand the meaning of messages, so let me tell the direct coding methods.

Source Destination Port No. Informations
--------------------------------------------------------------------------------------------
Server -> Client 3999-> 3224 [PSH, ACK] Seq=101743 Ack=11 Win=5840 Len=55
Server -> Client 3999-> 3224 [PSH, ACK] Seq=101798 Ack=11 Win=5840 Len=51
Client -> Server 3224-> 3999 [ACK] Seq=11 Ack=101849 Win=62992 Len=0

In this point PC Client terminated with abnormal error and send following reset message.

Client -> Server 3224->3999 [RST,ACK] Seq=11 Ack=101849 Win=0 Len=0

Next, Client restarted to make a new socket(3361) and to try to communicate with the same Server.

Client -> Server 3361->3999 [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1

Server -> Client 3999->3361 [RST,ACK] Seq=1 Ack=1 Win=0 Len=0

Client -> Server 3361->3999 [TCP Spurious Retransmission] Seq=0 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1


Server -> Client 3999->3361 [RST,ACK] Seq=1 Ack=1 Win=0 Len=0

Client -> Server 3361->3999 [TCP Spurious Retransmission] Seq=0 Win=8192 Len=0 MSS=1460 SACK_PERM=1

Server -> Client 3999->3361 [RST,ACK] Seq=1 Ack=1 Win=0 Len=0

......


Please let me know the correct code method of this case.

Thank you.

What I have tried:

Over 1 week, I wasted my time of this problem.

推荐答案

客户端关闭之前的连接后,它会尝试打开一个新连接。该尝试由服务器确认(ACK)但不被接受(RST)。因此客户端再次尝试它,由Wireshark指示为TCP Spurious Retransmission(数据包本身是一个与第一次尝试时发送的数据包相同的SYN数据包)。



所以问题可能在您的服务器代码中。检查手柄是否正确关闭(服务器将返回监听状态)并接受新连接(接受再次调用)。
After the client has closed the previous connection it tries to open a new one. This attempt is acknowledged (ACK) by the server but not accepted (RST). So the client tries it again which is indicated as "TCP Spurious Retransmission" by Wireshark (the packet itself is a SYN packet identical to those send upon the first attempt).

So the problem is probably located in your server code. Check there if the handle is closed properly (server will return to listen state) and new connections are accepted (accept called again).


这篇关于如果异常终止,如何重新连接最新的套接字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆