I have to write a server which have to accept clients on ports that they have specified.
Example : A wants to connect on port 1337, so server listen on port 1337. B on 1992 so server listen on 1992, etc…
I don’t know how to handle this.
Should I make a system like :
– All clients connects on the same port : XXXX ;
– The client’s 1st packet specify the port he wants ;
– The server binds / listens / accepts on the new port ;
– The server answers the client that it’s OK ;
– The client stops connecting on port XXXX and start connecting on the new port.
I don’t know if this kind of system is good, but I can’t figure out how else to do it.
Thank you, Florian
You’ll want some kind of master process or central table that keeps the room to port mappings. You’ll need clients to either connect to the master process or to some kind of “entry room” to get connected in the first place. Then, when they move from room to room, just look up the port they need to connect to, and refer them to the next port. All the central information can be kept in a database, if desired.