Ok I'm tring to write some code to make a server for a game that will accept 50 clients.
can I have 50 sockets all looking to one port without them being confused and reading each others data? Like i dont want player a's command to be interperated as player b's command by the server.
Since they are all looking at the same port im not sure if it will work. :confused:
Also if I use just 1 port is it still safe to check for new incoming connections on the port with a "listener" socket (all it does is see if some1 is there then accepts the connection to another open socket then releases itself.)
each accepted connection will be given a unique file descriptor. Use this to keep track of whats what.
ok so its alright to have one looking at the port for new connections and the others for the actual game data. Thanks
Your game SERVER will listen on a single port. All your clients will INITIATE a connection on that single port. Once the server ACCEPTS the connection, a new socket is opened (or new file descriptor, handle, whatever your OS uses). So each of those 50 connections will be on a different socket (and possibly a different port). You just have to juggle the communications with 50 different sockets. Hope thats clearer on how it works.
Thats pretty much what I ended up doing...