通过C#从服务器断开特定IP地址 [英] Disconnect a specific IP address from server by c#

查看:233
本文介绍了通过C#从服务器断开特定IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我想知道如何断开特定IP地址与谁通过c#(winform或asp.net)连接到我的服务器,并能够允许该IP通过端口站点和端口游戏再次重新连接到我的服务器!
就像您将游戏玩家踢出游戏一样,例如您已与服务器断开连接".

Hello everyone!

I want to know How can I disconnect a specific IP address from who connected to my server by c# (winform or asp.net) and able to allow that IP reconnect to my server again through port site and port game!
It just likes you kick gamer out game like "You''re disconnected from server"

推荐答案

这取决于您用于连接和通讯的方式.

您可以使用System.Net.Sockets.Stop http://msdn.microsoft.com /en-us/library/system.net.sockets.tcplistener.stop.aspx [ http://msdn. microsoft.com/en-us/library/system.net.sockets.socket.aspx [ http://en.wikipedia.org/wiki/Application_layer [ ^ ]).该特殊消息(可能只是一个控制字节)可以从服务器发送到选定的客户端.

—SA
It depends on what do you use for connection and communication.

You could use System.Net.Sockets.Stop, http://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener.stop.aspx[^].

You could also use one of System.Net.Sockets.Socket Disconnect methods, http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.aspx[^].

In general case, it will cause an exception on the client side. In my opinion, this situation lacks the graceful disconnection ceremony, but is perfectly valid. The client side should run the network communication code in a separate thread, should handle all the exceptions on the very top of the stack, and, in the case of network exceptions, be ready to reconnect.

Here is why I think working without graceful disconnection can be fine: the disconnection can happen non-gracefully anyway, by many reasons, such as system shutdown (in emergency of not), physical connection disruption and more. In all cases, the client part should handle all those events properly.



It looks like you need to display some reason for disconnection on the client side to show that the disconnection was done by the initiative of the server by some logical reason. My idea explained above still works. You can simply add some special "disconnection alert" message to your application-level game protocol (something you always have, please see http://en.wikipedia.org/wiki/Application_layer[^]). This special message (could be just one control byte) can be sent to a selected client(s) from the server.

—SA


这篇关于通过C#从服务器断开特定IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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