Problem kicking clients

Started by
3 comments, last by kzar 19 years ago
I am trying to write the code to kick clients off the server in my little chat program. (Mainly for if they don't have a unique nickname) The idea is I sent the client a kick packet including a explanation as to why they have been kicked and after that I close the socket to the client. The reason for closing the socket at the server is to stop third party clients ignoring the kick packet. The problem with this is that when I close the socket after the kick packet is sent to the client, the client doesn't get the packet before the connection has been closed. I am using SDL_NET and c, my program is the type where it loops round constantly instead of the type that has a dedicated thread that can wait for a message. I could add a delay between the kick packet being sent and the socket being closed but surely thats a bad idea as it would delay the whole program. Any ideas? Thanks
Advertisement
maybe something like this:
When you send the kick packet, put that client in a queue, along with a Current_Time+Kick_Delay_Time. When the time is right, boot them.
Hey thats a really good idea. I was also wondering about a time out delay for people not sending their nick after they had connected to the server and I could use it for that too. Thanks :)
on top of that, you could just have the client send back "ok, i know ive been kicked". when you get this, then close the socket. you should of course boot them anyway after the certain timeout period in case of a hacked client.
FTA, my 2D futuristic action MMORPG
Yea I just did a test. I ran the client on a different computer but instead of closing the connection properly I unplugged the network cable. The socket stayed open like I thought it might. I think I need a "heartbeat" like the eternal lands client uses. I think this should be seperate from the kicking timer though.

I thought in the server I could store a time for each client. Each loop the timer gets reduced and when it reaches 0 the client is kicked for timing out. But the client sends a message to the server every now and then to tell it that its still there which resets the timer.

To handle kicking I could have a seperate linked list of clients to kick. The linked list would store the pointer to the client's structure and a timer. This timer would be reduced and when it gets to 0 the client's connection closed.

edit: There are three things I'm not sure about though. How frequently should the client send a tell the server its still running? How long should the server wait before deciding a client is inactive? Should the server have to tell the clients that the connection is still ok too?

[Edited by - kzar on March 27, 2005 1:44:04 PM]

This topic is closed to new replies.

Advertisement