如何找到TCP / IP通信错误的原因。 [英] How do I find the cause of TCP/IP communcation error.

查看:189
本文介绍了如何找到TCP / IP通信错误的原因。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在VC ++中使用MFC



我正在编写一个客户端程序,使用带有KEEP ALIVE套接字选项的服务器的TCP / IP套接字通信,以及客户端从服务器接收每个数据。



1.如果或当客户端关闭套接字,我检查并在PC的命令行中运行'netstat',我总是找到相同的ip:portno是Fin_wait或Close_wait,意思是没有正确关闭。



2.此时服务器发送控制包同步到KEEP ALIVE信号,所以客户回复同步消息到服务器。



3.因此,由于对KEEP ALIVE操作的响应,客户端无法关闭同一个套接字。 />


4.当客户端尝试打开另一个套接字或对服务器执行新的和任何其他操作(如数据发送或接收)时,这不会产生正常结果,它会失败。



5.有时,客户端向服务器发出错误消息TCP Spurious Retransmission。这是上述问题的一个线索吗?



总之,我想随时关闭我的客户端套接字并与任何其他服务器建立新的连接。



此外,让我在这个KEEP ALIVE选项的情况下澄清使用TCP套接字的网络操作。



经过深入调查,closesocket的错误代码主要是大小写WSAENOTSOCK:描述符不是套接字。我不知道是什么导致这个错误代码。



这个TCP数据流有一个简单的图表。我想帮助你。



客户------------------------- -------------------------------------------- SERVER



1.请求---------------------->套接字打开------------------------->回复



2.回收数据< --------------------------- --------------------------------发送数据

Recv数据< ---- -------------------------------------------------- -----发送数据

Recv数据< ------------------------------- ----------------------------发送数据

Recv数据< -------- -------------------------------------------------- - 发送数据

Recv数据< ----------------------------------- ------------------------发送数据

Recv数据< ------------ -----------------------------------------------发送数据

Recv数据< --------------------------------------- --------------------发送数据

Recv数据< ---------------- -------------------------------------------发送数据

Recv数据< ------------------------------------------- ----------------发送数据



3.请求------------- ---------> closesocket -------------------------> ???



4.回复错误代码WSAENOTSOCK



谢谢。



我尝试了什么:



这个问题浪费了20多天。 />
我的程序已完成此错误的一半。

I have been using MFC in VC++

I am coding a client program using TCP/IP socket comm with Server which have a KEEP ALIVE socket option, and the client receive every data from the server.

1. If or when the client close the socket, and I check and run 'netstat' in command line of PC, I always find the same ip:portno is Fin_wait or Close_wait that mean not-closed rightly.

2. At that time the server send the control packet to sync of KEEP ALIVE signal, so the client reply to sync msg to the server.

3. So, the Client cannot close same socket because of the reponse to KEEP ALIVE operation.

4. When the client try to open another socket or to do new and any other operations to the server like as data sending or receiving, that makes no normal results, it fail.

5. Sometimes, the client make error messages "TCP Spurious Retransmission" to the server. Is this one clue of the above problem?

In conclusion, I want to close my client socket any time and make new connection to any other servers.

Furthermore, let me clarify the network operations using TCP sockets in this KEEP ALIVE option of situation.

After deeper investigation, the error code of closesocket is mainly case WSAENOTSOCK: "The descriptor is not a socket." I don't know what cause this error code.

There is simple diagram for this TCP data flow. I want for it to help you.

CLIENT --------------------------------------------------------------------- SERVER

1. Request ----------------------> Socket Open -------------------------> Reply

2. Recv Data <----------------------------------------------------------- Send Data
Recv Data <----------------------------------------------------------- Send Data
Recv Data <----------------------------------------------------------- Send Data
Recv Data <----------------------------------------------------------- Send Data
Recv Data <----------------------------------------------------------- Send Data
Recv Data <----------------------------------------------------------- Send Data
Recv Data <----------------------------------------------------------- Send Data
Recv Data <----------------------------------------------------------- Send Data
Recv Data <----------------------------------------------------------- Send Data

3. Request ----------------------> closesocket -------------------------> ???

4. Reply with error code WSAENOTSOCK

Thank you.

What I have tried:

More than 20 days wasted for this problem.
My program is half completed for this error.

推荐答案

为什么选择服务器发送keepalive数据包?在大多数情况下,客户端有兴趣保持连接打开。



您没有告诉我们使用的协议和典型的数据流。取决于它可能有助于定义断开连接消息。



甚至可能没有必要使用keepalive。另请参见 http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html [ ^ ]。



TCP Spurious Retransmission



这是Wireshark消息吗?然后他们可能会重复SYN数据包。另请参见虚假重传|包Foo |自2003年以来分析网络数据包 [ ^ ]。



我建议您重新考虑您的设置。如果我们应该帮助你,你应该告诉我们数据流,何时以及为什么要以编程方式关闭连接以及如何在两侧检测到关闭的连接(保持连接,超时,发送失败)。





Why you choose the server to send the keepalive packets? In most cases the client is interested in keeping a connection open.

You did not tell us about the used protocol and the typical data flow. Depending on that it might help to define a disconnect message.

It might be even not necessary to use keepalive. See also http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html[^].

"TCP Spurious Retransmission"

Is this a Wireshark message? Then they might be repeated SYN packets. See also Spurious Retransmissions | Packet Foo | Analyzing network packets since 2003[^].

I suggest to rethink your setup. If we should help you should tell us about the data flow, when and why connections should be closed programmatically and how closed connections should be detected on both sides (keepalive, time outs, sending fails).


引用:

经过深入调查,错误closesocket的代码主要是大小写WSAENOTSOCK:描述符不是套接字。我不知道导致此错误代码的原因。

After deeper investigation, the error code of closesocket is mainly case WSAENOTSOCK: "The descriptor is not a socket." I don't know what cause this error code.

此返回代码的最常见原因是套接字已被关闭(假设套接字已成功创建)。如果您连续两次为有效套接字调用 closesocket ,则第二次调用将失败并显示此错误代码。因为套接字被系统重用,所以不保证这种行为(特别是如果已经过了一段时间)。



避免重复调用的常用方法是分配 INVALID_SOCKET 套接字关闭后检查此值然后再尝试关闭它。



我建议发布一些代码片段以获得进一步的帮助。请尝试仅发布必要的代码(这可能很难,因为这些错误需要清楚地了解正在发生的事情)。

[/ EDIT]

The most common reason for this return code is that the socket has already been closed (assuming that the socket has been successfully created). If you call for example closesocket for a valid socket two times in a row, the second call will fail with this error code. Because sockets are reused by the system, this behaviour is not guaranteed (especially if some time has elapsed).

A common method to avoid duplicate calls is assigning INVALID_SOCKET after a socket has been closed and checking for this value before trying to close it.

I suggest to post some code snippets to get further help. Please try to post only necessary code (which might be difficult because such errors require a clear view on what is going on).
[/EDIT]


这篇关于如何找到TCP / IP通信错误的原因。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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