Click here to Skip to main content
15,888,216 members
Please Sign up or sign in to vote.
3.00/5 (4 votes)
See more:
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"
Posted
Comments
Shahin Khorshidnia 27-Feb-12 14:50pm    
Try to learn SOA
Sergey Alexandrovich Kryukov 27-Feb-12 17:02pm    
If you elaborate on that, it could be a useful answer. Not that this comment is as useful.
--SA
Shahin Khorshidnia 27-Feb-12 17:24pm    
Of course SA, but it was a comment (as a paltry help)
I didn't write it as a solution. ;)
Wonde Tadesse 27-Feb-12 21:47pm    
What SOA got to do with this question ?
Shahin Khorshidnia 28-Feb-12 5:17am    
You know object-oriented aggregates all a developer needs for remoting, client, server, transport protocols and ...

But:
Perhaps it woild be more accure to say pulpcorn aksed a question about disconnecting IP Address, SA answered to the question and his solution has been accepted. In all fairness it's a useful solution and I voted +5. My comment was not wrong too (As a comment)
I have no idea why you follow the comment, my friend. But If there are any more questions, please do not hesitate to ask.
Thank you

1 solution

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.

[EDIT]

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
 
Share this answer
 
v3
Comments
pulpcorn 28-Feb-12 1:01am    
hmm!

My client game will auto display text "You're disconnected from server" when it couldn't connect to my IP and Port server!
So I just thought like this: if I could block a specific IP address who connected to my server, it would solve my issue!

like:
Detect IP Address
Disconnect IP Address
Reconnect IP Address

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900