正确关闭服务器. [英] Closing a server properly.

查看:338
本文介绍了正确关闭服务器.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用TCP连接的服务器和客户端.当我关闭服务器时,如果客户端已经打开了连接,它将无法检测到没有服务器要连接,并且尝试执行发送操作.我使用最少的必要代码连接两个应用程序.我想知道什么是需要停止或关闭的东西,以完全确保服务器和客户端之间的连接是关闭的,我可以在on form close事件中完成所有操作.抱歉,如果我没有足够清楚地解释,将不胜感激.

I have a server and a client connected using TCP. When I close the server, if a connection has already been opened by the client it fails to detect that there is no server to connect to and tries to perform the send operation anyway. I connect the two applications using the bare minimum amount of code necessary. What I want to know is what are the things that need to be stopped or closed to completely ensure that the connection between the server and the client is closed, and can I do it all in the on form closed event. I apologise if I haven''t explained clearly enough, any help will be greatly appreciated.

推荐答案

看看这篇文章:

http://www.codeproject.com/KB/IP/BasicTcpServer.aspx [ ^ ]

在这里您可以看到有一个OnDropConnection,它将通知客户端连接已关闭.然后,客户端会知道发送操作不会成功.

祝你好运!
Have a look at this article:

http://www.codeproject.com/KB/IP/BasicTcpServer.aspx[^]

Here you can see there is a OnDropConnection that will notify the client that the connection is closed. The client then would know that a send operation isn''t going to succeed.

Good luck!


这篇关于正确关闭服务器.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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