Writing a Game Tracker Server...

Started by
1 comment, last by markr 19 years, 2 months ago
I am currently in the process of writing a Game Tracker Server. The game player connects to the server and requests a list of all available servers, or adds his own server to the list. In the future it may need to support a virtual lobby where players can chat. I am wondering what are some of the approaches for dealing with possibly thousands of client connections all requesting data at once? Currently, my Client\Server class is written using TCP/IP. The Server thread listens for connections, and for each new connection, creates a new Client Class, which in turn creates a new thread to handle sending/receiving packets. I get the feeling that creating a new thread for every new client is not the best idea. I have thought about using a Thread Pool. Besides the overhead of constantly creating and destroying threads, what other benifits would using thread pooling give me? Also, how do you handle the fact that you have a limited number of threads initially allocated, say 10, and you have 11 clients requesting connections. Thanks!
Advertisement
Why use threading? You don't need to constantly update real time statistics or seperate gamelogic from network logic. Just iterate each client in 1 single thread and handle their data.

If you insist on going with threads, set a max. number of users per thread. For instance, have the server handle 64 connections per thread. When a new connection is made, you iterate over the EXISTING threads, check the number of connections per thread and if lower than 64, have that thread accept the connection.

When all threads are full, spawn a new thread and add the connection to it. When a connection is closed, and a thread has 0 connections, terminate the thread.

To optimize it even further, you could do checks at a set interval(say, every 5 minutes), find the thread with the lowest number of connections. Check all the other threads and add the numbers. If the total number of free slots in the other threads are larger than the thread with the lowest numbers, move the connections and terminate thread. This will make sure there aren't alot of threads which only handle 5 or 6 players but keep the number of threads to a minimum.

Toolmaker

Probably your best bet would be to use your favourite web server-side technology (hint: PHP, ASP.NET etc) to create a page which receives commands / sends responses via HTTP.

HTTP is very easy to implement (plus there are heaps of libraries which do it already), and it's ideal for what you want.

Have a file / database containing the list of servers. The PHP page (for the sake of argument) could have the following parameters:

http://serverlist.mygame.fake/servers.php?command=list

Might list the servers.

Doing a HTTP post containing the fields command=add&serverip=my.ip.here might add a server.

You would need a process which periodically checks servers in the list to make sure they really are active and running the game (if not, drop them). Servers added would not become visible immediately, they would have to wait for a check.

This check would be done by some sort of background program, which would share network code with the game itself, and behave as a small client which just connects to the server and asks it "are you there" and any other pertinent info (version, game options, server name etc). This info would be added to the list. The clients would use this to display to the user and filter out games which are the wrong version etc.

Have a look at how bzflag does it...

Mark

This topic is closed to new replies.

Advertisement