vb.net客户端/服务器代码有关连接的一些问题 [英] vb.net client/server code some questions about connection

查看:357
本文介绍了vb.net客户端/服务器代码有关连接的一些问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当客户端切断连接时,有没有办法让服务器知道并从Online-List中删除客户端?

解决方案

在网站上?不,不可靠。



你可以做的事情,但他们确实依赖于用户正确地做事,并不总是工作。



最好的方法是对 Session_OnEnd事件 [ ^ ]并将其记录在那里,如果他没有;自动登出。


好问题。



非常常见的经典方法是优雅断开连接。首先,无论你做什么,你都必须开发一些应用程序级协议 https:/ /en.wikipedia.org/wiki/Application_layer [ ^ ])。许多人隐含地开发这样的协议或认为他们没有开发任何协议,但实际上他们确实如此。实现它并明确定义协议总是更好。在此协议中,客户端可以向服务器发送特殊消息我想断开连接,然后服务器发送确认将断开连接并删除客户端的远程套接字或 TcpClient 来自沟通。 但它值得做吗?



我以前在一些文章中看过这样的建议,但我认为这是一个典型的虚假功能。为什么要开展这种优雅的断开连接?以下是这些事情:当断开连接不优雅时,有很多情况。客户端应用程序可以通过终止进程来终止,客户端计算机可以随时关闭,等等。同时,如果正确设计应用程序代码,服务器无论如何都会收到通知,即使非正常断开连接。你只需要设计你的线程并正确使用异常处理。



请查看我过去的答案:

我如何知道如果AA Tcp连接是结束 [ ^ ],

套接字编程中的业余问题 [ ^ ],

多个客户来自相同的端口号 [ ^ ]。



-SA

whenever client cut off the connection,is there any way to let the server know and remove the client out of Online-List?

解决方案

In a website? No, not reliably.

There are things you can do, but they do rely on the user doing things correctly, and don't always work.

The best way is to react to the Session_OnEnd event[^] and log him out there, if he doesn;t log himself out automatically.


Good question.

A very usual classical approach is "graceful disconnection". First of all, no matter what you do, you have to develop some application-level protocol (https://en.wikipedia.org/wiki/Application_layer[^]). Many develop such protocol implicitly or think they don't develop any protocol, but actually they do. It's always better to realize you do it and define the protocol explicitly. In this protocol, a client can send a special message to the server "I want to disconnect", then the server send confirmation "will disconnect" and remove the client's remote socket or TcpClient from communication. But does it worth doing?

I used to see such advice in a number of articles, but I think this is a typical bogus feature. Why developing such graceful disconnection? Here is the things: there is a number of situation when disconnection is not graceful anyway. The client-side application can be terminated by killing the process, the client-side computer can be shut down anytime, and so on. At the same time, the server will get the notification anyway, even with the "ungraceful" disconnection, if you design your application code properly. You just need to design your threads and use exception handling properly.

Please see my past answers:
How Do I Get To Know If A A Tcp Connection Is Over[^],
an amateur question in socket programming[^],
Multple clients from same port Number[^].

—SA


这篇关于vb.net客户端/服务器代码有关连接的一些问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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