识别 VB.Net 中 Socket 服务器和 Socket 客户端之间的连接丢失
朋友们,
我编写了一个套接字客户端,它将向套接字服务器发送一些数据并从服务器获取一些响应。该进程每 2 秒运行一次。
现在我需要知道的是我们如何识别服务器和客户端之间的连接丢失?
我需要在客户端实现这个。如果没有连接,则客户端应自动关闭连接。一旦与服务器的连接在下一次尝试中可用,它应该自动连接。
提前致谢!
Friends,
I wrote a Socket Client which will send the Socket Server some data and get some response from Server. This process will be running once in every 2 seconds.
Now what I need to know is How we can identify the connection lost between Server and Client?
I need this to be implemented in the Client side. If there is no connection then Client should automatically close the connection. Once the connection with the server is available in the next attempt it should connect automatically.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是 vb.net 开发人员,但这就是它在大多数语言中的工作方式。
写入丢失/关闭的连接将失败,然后客户端将知道他需要重新连接。
在完成之前不可能知道与服务器的连接尝试是否会成功,因此您的客户端应该尝试在循环中重新连接,并在每次连接尝试之间有一个睡眠/等待时间段。
I'm not a vb.net developer, but this is how it works in most languages.
Writing to a lost/closed connection will fail, the client will then know that he needs to reconnect.
It's never possible to know if a connect attemt to a server will succedd before you have done it, so your client should try to reconnect in a loop with a sleep/wait period in between each connection attempt.