多次尝试后,套接字停止连接 [英] Socket stops to connect after several attempts

查看:84
本文介绍了多次尝试后,套接字停止连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我最近开发了通过TCP工作的客户端和服务器应用程序。有时客户端应用程序丢失连接,所以我让它重新连接到服务器(我听说过Keepalive,但由于时间不够谷歌它)。问题是
客户端连接 - 一段时间后失去连接 - 连接 - 一段时间后失去连接 - 尝试连接并获得异常"主机在一段时间后没有响应"或类似的东西。我已经调试了服务器,发现服务器只有
没有尝试连接。我试图创建新的套接字(_socket = new Socket();)并通过它连接(不成功)。唯一有帮助的是 - 重新启动应用程序。所以我的问题是:


- 客户端停止连接的原因是什么? 


- 我该如何修复它?

解决方案

嗨Nisefal,


>> - 客户端停止连接的原因是什么? 


根据您的描述,我不知道导致问题的原因,正如您所说,重启应用程序将工作,您重启的应用程序,客户端或服务器。如果你重新启动服务应用程序,它运作良好,也许服务应用程序很忙,这可能是
没有响应客户的请求。 


>> ; - 我该如何解决?


请参考以下类似问题,请尝试通过$ b $查看流量获取线索b Wireshark


https://stackoverflow.com/questions/38701356/tcpclient-socketexception-with-timeout-after-20s-no-matter-what


祝你好运,


张龙 


Hi. I have recently developed client and server applications that works via TCP. Sometimes the client application lost connection, so I make it reconnect to server(I've heared about Keepalive, but due to lack of time haven't google it). the problem is that client connects - lose connection after a while - connects - lose connectin after a while - tries to connect and get exception "Host hasn't responed after a perioud of time" or something like this. I've debuged server and found that server just have no attempt of connection. I've tried to create new socket(_socket = new Socket();) and connect via it(unsuccessfuly). The only thing that helped - was restart of application. So my questions are:

- What could be the reason that client stops connecting? 

- How can i fix it?

解决方案

Hi Nisefal,

>>- What could be the reason that client stops connecting? 

Based on your description, I am not sure what cause the issue, as you said, restart application will be work, what application you restart, client or server. if you restart serve application, it works well, maybe the serve application is busy, which could not response client's request. 

>>- How can i fix it?

Please refer to the following similar issue, please try to get the clue from looking at the traffic with Wireshark

https://stackoverflow.com/questions/38701356/tcpclient-socketexception-with-timeout-after-20s-no-matter-what

Best regards,

Zhanglong 


这篇关于多次尝试后,套接字停止连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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