Take the 2-minute tour ×

I NEVER, EVER did ANY sort of network code in C++, I don't know even the libraries that exist, but a popular demand for my game is online leaderboards...

So, what sort of libraries I should research into?

My game is multiplatform (win, gnu, mac), uses C++, ClanLib 1.0 and Lua. Also the engine is zlib (so proprietary stuff that I cannot release source don't work)

share|improve this question
My first recommendation would be "don't use C++ for a leaderboard server". Implement it in a higher level language, which will usually offer functionality to take care of handshakes, sessions and such. Most of them allow communication via SOAP, which is easily supported in C++, so your client can use it to contact the server. Personally, I'm creating my generic leaderboard system in .NET WCF (C#). –  Elideb Dec 6 '11 at 0:04

4 Answers 4

First question, how much do you care about cheating? Making a simple webapp for leaderboards is probably pretty easy, but it will instantly be spammed out of existence. I would look at curl as a decent async HTTP library that you should be able to integrate into just about any client code. For the server side, I assume you have no budget for dedicated servers, so Google App Engine might be a good match if you know either Python or Java.

share|improve this answer
I second using Google App Engine. Even if your game gets massively popular, you should still easily be able to fit it inside the free tier. Also, never having to worry about the server platform is a HUGE plus. –  drxzcl Aug 31 '10 at 8:37
The problem is that the game itself I have no idea on how to prevent cheating... I mean, it is probably kinda easy to run Cheat Omatic (search for this software, it is pretty cool), and edit the scores, or any other number in the memory (actually using it I could even create more units than normally allowed in Age of Empires for example). –  speeder Aug 31 '10 at 23:07
There are something like google app engine that don't use python or java? I know bazillions of languages, but not those two :/ –  speeder Aug 31 '10 at 23:08
Not that is free. There is Heroku if you know Ruby/Rails, and I've heard it isn't too expensive. As for preventing cheating, I would need to know a lot more about the game. PunkBuster and Valve's Anticheat might be options for client hardening, but you will need some kind of server-based solution if you want to be really sure. Alternatively just have entries on the leaderboards age off after a week or so, most spammers will lose interest. –  coderanger Aug 31 '10 at 23:40

It all begins with protocol design. What do you need to transmit over the wire? What kind of handshakes and verification mechanisms are needed? It could be as simple as a network packet is sent every time a game is over. It would simply contain the username with the score, for example { "Joel", "33" }

The problem is that how do you confirm the score was achieved in a legitimate way? Perhaps someone simply analyzed your protocol packets with a network analyzer and concluded that only a username with the score is sent. Then he manually creates this packet and sends it. This is what coderanger meant by "getting spammed out of existence".

As for storing the leaderboard itself, I would recommend using a database, like SQLite. This gives you thread-safe and concurrent saving/access mechanism to the leaderboard. The underlying database takes care of synchronization.

For the networking code itself, you need two parts. Something to send the data to the server and something that consumes and processes it at the server side. As coderange mentioned, it could be something as simple as HTTP/XML/JSON HTTP GET/POST and then a web server running on server side would consume that in a web service. The good part is that you don't have to deal with any of the networking code for the server's side as that is taken care of by the web server.

share|improve this answer
MySql would work? The country where I live MySql hosting is pretty common and cheap (well, sorta cheap). –  speeder Aug 31 '10 at 23:08
Absolutely. Almost any database would suit this scenario. –  randomguy Sep 2 '10 at 20:05

From my experience there are multiple steps you will have to go through. Choosing C++ libs is not the most pressing of them. There are more important things you will have to consider.


Concerning the hosting of your leaderboard you will have to make a choice. Either you rent servers and you can chose the technologies you want and do what you want. Or you rent hosting space and you will have to work with the techs at your disposal. Or you will use one of the cloud solutions and have to work with the constraints and advantages of those.

It's all a question of cost time investment and reusability. If you already have server you can try to host your leaderboards there, if you already use a hosted site you can start prototyping with that.

Personally I would recommend renting a server or a virtual server at first.

This question deserves a thread of its own and should be answered independently if you have a hard time dealing with it.


Which server technologies you will use is up to you and depends heavily on the hosting solutions you will choose.


Of course you can start with an SQL storage, MySQL is pretty cheap efficient and simple to use, supported by most hosting providers. This is the solution I have been using. But beware when it comes to scalability you might regret using it later.

There are other better solutions. ERLANG based DB servers like CouchDB are quite popular. One of them, RIAK is simple to distribute across multiple servers, efficient, uses JSON and is used by big names like Mozilla and GitHub.


You will not give access to your data storage directly from your client apps. You will need to write an application to manage authentications, authorizations, some logics and DB access.

Java, PHP and perl are often used to write web services which provide these functions, are well supported by hosting providers and have strong dev communities.

But if you want to avoid the overhead of a full fledged HTTP server like Apache you should use nodeJS. It is a very efficient low footprint and fast solution. Used by e-bay, Microsoft and Linked-In. It integrates very nicely in setups that use JSON for data exchange.


Your leaderboard design will start with the data storage. What do you want to store. How do you want to store it and for how long?

You want to store the scores of course (time, distance, points...), but with that do you have multiple levels? then you will need to store the level IDs, do you support multiple platforms? If so the difficulty of the game might be different on different platforms for technical or demographical reasons, will you store that too...

How do you want to sore it? Do you want to keep only the best scores, replacing all previous ones done by the player on the same platform/level/context? Or will you store everything to keep track of all the possible scores? Will you hold on to discarded previous scores for data mining?

Once you answered these questions you can start thinking about the implementation.


You will want to transfer data from and to the clients. For this you will have to create a good communication protocol.

The choice of the underlying protocols is secondary in this step (HTTP, TCP, UDP). Whatever your choice is you will have to craft your own protocol carefully so you will be able to handle errors, changes in the protocol, application updates, etc...

So make sure your server application can handle providing data to applications which are updated and applications which run older versions as well.

Make sure to protect the data transferred to and from the server. Be careful about protecting score uploads, you can use hash keys, encryption and other mechanisms to protect your server from cheaters.

Wherever you chose to send binary or text (JSON, XML) data is up to you. But for flexibility and compatibility I would recommend JSON. Avoid XML. Use binary if you really need/want it.

This topic deserves more attention and you might have more questions...


The client will have to integrate with your solution. You should not chose your server tech and protocol layers based on the client's language. You should integrate your server solution to your game.

If you chose JSON over HTTP there are libs for that.

There are C/C++ libs for JSON, I would recommend using them. You can write your own if you like. I wrote a small JSON lib in a matter of hours. It's now used in games across dozens of platforms.

Concerning HTTP in C++ use something more modern than CURL. cpp-netlib should do.

Beware of the character encodings etc when sending the data though.


To be able to store and display best scores for your users they will have to be identified somehow. There are multiple ways.

The simplest being none. Use the Enter Name Here field to display the names on the leaderboard.

You can also ask the players to register... this is often a process which discourages players.

One way I used a lot is Facebook authentication. This way you can pass the auth data to or through your server and get data about the friends and serve personalized leaderboards i.e. Global leaderboard, friends leaderboard...

share|improve this answer

Client side: The application or game uses a http lib like libcurl or the sfml-network package. Server side: A simple solution with php and mysql, postgresql or sqlite3. The php files are hidden or inaccessible to the user.

share|improve this answer
This answer could be improved by writing about how to use those technologies, instead of just listing them. –  Josh Petrie Nov 5 '12 at 16:52

Your Answer


