pls can anyone tell me how to block new connections in winsock
Printable View
pls can anyone tell me how to block new connections in winsock
New connections to what? From what?
i have a chat winsock app that must block new connections when a total of 12 connections have been established by 12 different ip.
I assume you've have to be using an array of Sockets for that - why can't you just keep note of how many are created, then abort accepting the connection once the limit has been reached?
I always setup a static array defined as socket objects, then create a second array of booleans that indicate if the corresponding location in the Socket array is in use. Then, I loop through my sockets and find empty places to create new ones. Likewise, I remove the socket when I'm done. In my case, I'd just count the number of Trues in my array of booleans to determine how many connections I have.
Good luck!
I'm developing a chat application too. I work with serialized objects, wich are received and sent back from and to the server, respectively. What I do is really simple, I define an static var, wich is increased when a client connects to the server and decreased when he disconnects from it. I also keep a private const that contains number of users that will be accepted simultaneously. When you receive a new connection, the only thing you have to do is to check if static var is equal to private const. In that case you must say to the client that his try of connection has failed. And for doing that you will always have to first accept the socket, independently of the current number of user connected, and then do the condicional sentence.
It's just the way that I'm working with that.
I hope that you find it useful at least.
Regards!.
i found a way out of it.
thanks