TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Resources for multiplayer game server development

12 pointsby mcantoralmost 14 years ago
I have been developing for many years in the friendly world of web apps, where HTTP requests are not persistent and the only shared resource is a database. I recently began an ambitious personal project, for both learning-by-reinventing-the-wheel and scratching my own itch, to write my own mostly-text-based game client and server. Think MUDs/MUCKs but maybe with avatars.<p>I've had great success on the client side so far. My language of choice for server and client is ruby. Qt has been kind to me, especially since this is the first non-trivial thick client app I've written.<p>On the server side I am somewhat at a loss. I need to handle multiple persistent connections with data being asynchronously transferred between the server and its various clients. I am spinning up a TCPServer which spins up a thread for each socket connection.<p>I am fairly certain that sockets are not thread-safe, and that some form of resource lock (such as a mutex) will be required around socket read/write operations. However, without any background in this kind of programming, I have no confidence that I am even reinventing the <i>right</i> wheel!<p>I do not want to use EventMachine or GServer because I don't understand what they do. My goal here is not "write a game", but "write a game and learn how some of the lower-level stuff works".<p>I've found some OK resources via Google, but I would <i>love</i> HN's recommendations for books, ebooks, websites, example implementations to study, bits of wisdom, and so forth.<p>Thank you!

2 comments

stonemetalalmost 14 years ago
The link is about FPS networking so not really applicable to what you are doing, but an interesting read non the less. <a href="http://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking" rel="nofollow">http://developer.valvesoftware.com/wiki/Source_Multiplayer_N...</a><p><i>I am spinning up a TCPServer which spins up a thread for each socket connection.</i> I know this is just for learning purposes but this really isn't the way to do it. Use select or your platform specific enhanced version(kqueue, epoll, IO completion ports.)<p>I would probably have a separate communication thread handling all your sockets(with select) with two queues of messages, one for each direction. While the main thread handles processing messages.<p>This is probably a little too entry level but it makes a good reference. <a href="http://beej.us/guide/bgnet/" rel="nofollow">http://beej.us/guide/bgnet/</a>
metachrisalmost 14 years ago
Take a look at the c10k problem, a classic resource for this problem domain: <a href="http://www.kegel.com/c10k.html" rel="nofollow">http://www.kegel.com/c10k.html</a><p>You probably don't want to spawn one thread per connection, but get notified by the operating system when one of a bunch of TCP socket connections has an event for you to handle. You can achieve this by the kernel calls epoll, poll, select, kqueue. For Python, I recommend taking a look at tornado (<a href="https://github.com/facebook/tornado" rel="nofollow">https://github.com/facebook/tornado</a>), an asynchronous socket handling framework. In particular the "io-loop", which you could use for handling the connections.<p>As for serialization protocols, don't roll your own but consider JSON for maximum flexibility, and protocol buffers for maximum efficiency. For communication between servers consider well known libraries and protocols such as AMQP (eg RabbitMQ) and Redis pubsub.<p>Be sure to read up about Linux kernel settings to improve the number of maximum open sockets, etc. Here are several good readings referenced: <a href="http://serverfault.com/questions/10852/what-limits-the-maximum-number-of-connections-on-a-linux-server/10919#10919" rel="nofollow">http://serverfault.com/questions/10852/what-limits-the-maxim...</a><p>Also, you'll want to get familiar with some tools you'll be using a lot, such as <i>lsof</i> and <i>netcat</i>.<p>About the infrastructure design: you'll most likely end up with several different server applications and possibly a number of simultaneous running instances. Consider Amazon EC2 micro instances or something similar to start with.<p>I'd recommend to experiment with building several prototypes before the real product, getting to know the approaches, architectures, bottlenecks, etc. Enjoy the learning experience!<p>Finally, spend enough time on the supporting tools, such as automatic deployment (chef, puppet, fabric), automated clients, etc. which will make your life a lot easier! :)