Just to make sure I am understanding this. So I would, of course, start a listening socket and bind it and everything just like normal. I would listen on that socket and wait for a connection. Once I get a connection from a client I move the connection to its own thread on the server. How would I go about moving it to its own thread? That thread would go into a loop listening for incoming messages using a while loop probably. As new connections are made new threads are created each time. When a connection is dropped/ disconnected the thread ends. Each thread will only handle the data for their particular connection. Am I understanding correctly?
How do I go about creating threads? What would be a good way to do it efficiently? I found this when searching for multi-threading in c++
http://www.devarticles.com/c/a/Cplusplus/Multithreading-in-C/ I am reading through it as we speak, maybe I will get some idea of a good way to do it.
I figure the best way to handle the other servers is for them to connect to the main server on a completely separate port from the clients and have them all running in separate threads like the clients.
Or, maybe a better way to do it could be for the other servers to connect to the main server to give some basic data, IP and name would be all, that is stored on the database when the other server first comes online, then disconnects from the main server after the data is send and is confirmed that it was added to the database. When a client connects to the main sever and asks for a server list the main server send the client the IP and name of the servers. Then the client tries to connect to the other servers and if they are full tell the client, otherwise connect. Then when a server shuts down, tell the main sever and have it remove the servers data from the database before it shuts down completely.
The "other servers" would be for the client to connect to so they can actually play online with other players. Think of it as matchmaking like in Halo or Call of Duty, or really any other multiplayer game on Xbox Live.
Would it be a good idea to disconnect the client from the main server once the server list is sent to save bandwidth? The connect only when to log out or to update the server list?
Thanks,
Legobear154
I appreciate all the help!