为什么我的客户端服务器套接字连接保持断开 [英] Why does my Client Server Socket Connection Keep Disconnecting

查看:157
本文介绍了为什么我的客户端服务器套接字连接保持断开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户端服务器应用程序在C#.NET中使用套接字writter。

I have a client server application writter in C# .NET using Sockets.

我经常收到日志消息(例如约4每小时)说这句话的消息,

I often get log messages (say about 4 per hour) saying this message,

An existing connection was forcibly closed by the remote host

在这种情况下,这里的错误是发生在服务器的一面。

In this case here the error is occuring on the 'server' side.

我决定使用Wireshark分析什么正在发生,而我得到这个。有没有延迟,这是所有在几秒钟发生的事情。

I decided to use wireshark to analyse what is occuring, and I get this. There are no delays, this is all happening within a couple of seconds.

Server > Client [PSH, ACK] Seq=55653 Ack=4472  Win=63940 Len=148
Client > Server [ACK]      Seq=4472  Ack=55801 Win=4038  Len=0
Server > Client [PSH, ACK] Seq=55801 Ack=4472  Win=63940 Len=148
Client > Server [ACK]      Seq=4472  Ack=55949 Win=4001  Len=0 
Server > Client [PSH, ACK] Seq=55949 Ack=4472  Win=63940 Len=142
Client > Server [PSH, ACK] Seq=4472  Ack=55949 Win=4001  Len=31
Client > Server [RST, ACK] Seq=4503  Ack=55949 Win=0     Len=0

因此​​,客户端和服务器发送自己(PSH)之间的东西,并确认的东西(ACK)。突然间一个RST是存在的。这根据维基百科是一个复位,这种复位对应于一个现有的连接被强行......的消息,我得到上面。

So the client and server are sending stuff between themselves (PSH) and acknowledging stuff (ACK). All of a sudden a RST is occuring. This according to wikipedia is a reset, and this reset corresponds to the 'An existing connection was forcibly ...' message I get above.

真正意思有关系吗?这是否意味着复位导致此问题?我认为这个问题的答案是否定的,什么更有意义的是,复位是问题的结果?即在服务器端的插座模出于某种原因,和客户端发送复位到服务器以一种尝试,并唤醒。

What really does that mean though? Does this mean that the reset causes the issue? I think the answer to that is no, and what would make more sense is that the reset is a result of the issue? I.e. The socket on the server side dies for some reason, and the client sends the reset to the server to kind of try and wake it up.

思考?

推荐答案

有时候,一个行为不端的客户端会得到或发送就是了,然后立即退出(关闭套接字,并突然切断连接)的内容。这是很正常的,偶尔上的裸到互联网的任何服务。

Sometimes a misbehaving client will get or send what it wants to, then immediately quit (closing the socket, and abruptly severing the connection). It's normal to see that occasionally on any service that's exposed to the internet.

如果这是你自己的code是造成这种情况,请确保您发送的任何我现在正在做的命令(一个常见的​​一种是退出),并正确关闭的连接关闭它之前。除此之外,他们唯一重置,你应该导致将涉及您的上网剥落了。

If it's your own code that's causing this, make sure you send any "i'm done now" command (a common one is "QUIT"), and properly "shutdown" the connection before you close it. Aside from that, about the only resets you should be causing would involve your internet access flaking out.

这篇关于为什么我的客户端服务器套接字连接保持断开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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