penpen
penpen

Reputation: 53

How to create multiplayer game with contacts and realtime communication, without creating server?

I would like to have some advices about my project. I am currently developing a musical application/game in C++/Qt, with a multiplayer mode, and I have the following requirements (ideally):

What would you recommend to do this?

I was thinking of using xmpp protocol, so I can connect to google/jabber and retrieve contacts, chat with them. Actually this part works, but then I don't konw how to send/receive realtime datas. For the realtime part, I was thinking of using direct TCP communication, but I need to know external ip of my contacts, and I have no idea how to do it. I was thinking to automatically send my external ip and tcp port to all my contacts every time I connect, but I didn't find solution to retrieve external ip from code. So I'm a bit stuck. Any advice?

Is there alternative solutions? alternative protocols?

Thanks you,
Laurent

Upvotes: 0

Views: 1690

Answers (1)

Wug
Wug

Reputation: 13196

You're going to have a really hard time avoiding writing a server, for realistic, practical, and performance reasons:

  1. Many residential internet connections are behind firewalls (at the ISP, local router, or OS level) that limit accepting connections from outside the network. NAT further complicates accepting connections from the internet on a LAN.

  2. There are precious few methods of internet communication that are serverless, and those that are are subject to using local peer discovery to find peers. Most LPD traffic will not make it off your lan, the ISP will filter it (otherwise you'd be able to "locally" discover peers on the entire internet).

  3. Bandwidth can be a concern for games. Not everyone has a high speed internet connection yet (though market penetration of fiber optics and fast DSL is pretty high at this point), and you'd end up with problems connecting slower hosts to a large swarm.

  4. Servers facilitate star-like networks, which are very efficient. Other network topologies exist, but many suffer from drawbacks that severely inhibit their ability to scale.

    • Star networks, for example, for clients, require O(connections) = O(1), O(bandwidth) = O(1), and O(latency) = O(1).

    • Fully connected networks require every client to be connected to every other client, so O(connections) = O(bandwidth) = O(n), and O(latency) = O(1).

    • In ring networks, each client connects to 2 neighbors and messages of distant clients are forwarded. Therefore, they have O(connections) = O(1), but O(bandwidth) = O(latency) = O(n).

If all you need is a chat system, or want badly enough not to write your own server that you're willing to piggyback the entire online experience over a chat server, you could probably rely on something like an XMPP server.

If you choose to go that route, make sure that proper authentication and encryption is used wherever necessary to protect user's private data (passwords, etc). I recommend using a cryptographic authentication scheme that allows clients to authenticate other clients (such as a challenge/response scheme, or something else). Or, you could mediate all authentication with a central service.

Keep in mind that many chat services will not want to provide your project with free bandwidth. Even if you do decide to use XMPP as the heart of your multiplayer protocol, expect to be running your own server.

Upvotes: 2

Related Questions