Multiplayer racing game

I am about to make a 2D top down racing game where players can compete against each others over Internet.

I made a similar game earlier, but that time I used a server, and this time I need to use a server-less approach for several reasons, connecting players directly.

I have no experience in how to set up a direct connection between two clients and let them exchange data, so I wonder what’s the basic fundament needed from your experience?

Assume I already got the clients IP addresses (matchmaking will be solved through a third party solution).

I think I need both TPC and UDP. And my biggest worry is Firewalls. So, can anyone advice me a method that would work for most people on windows system out there? Keeping in mind this is an action game.

A code snippet showing how to get a stream bytes to the other client over UDP/TCP, as well as how to receive it, would be great.

Thanks :slight_smile:

well, about firewalls, user will must allow the game to use the port if he plans to connect to matchmaking service so if you send game data on same port where matchmaking is sending it will work. The only problem with firewalls as I know are when you try to connect to computer without it doing anything, then you’ll get blocked.

Well, you could always user Darkstar 8)
The SDK even comes with a complete match maker in source code.

Otherwise, your big issue is firewalls. If you are using a server i na start-configuration then TCP is no problem because out-going connection are almost always mapped for you. UDP is also not a problem on modern home firewalls so long as you start from the client and send a packet to the server first to get it to auto-map the UDP port and then look at that packet to see what the mapped incomign UDP port was.

Peer to Peer is trickier. You more or less cannot accept an incoming TCP connection behnind a consumer firewall unless you manually configure the firewall to map a port on the firewall to a port on the machine yo uare playing on.

There is a trick sometiems called “UDP punch through” or “UDP introduction” where you cna use a server to help two clients behind firewalls establish a P2P UDP connection.

But at the end of the day, you pretty much need a server to solve firewall issues no matter which way you do it. Darkstar handles this for you and is a “star” type system. Otherwise you might want to investigate JXTA and use their servers…

Thanks, Darkstar sounds interesting. I am googling for it now. Do you have any pointers to some basic tutorials matching a couple of clients, then allowing them to interact directly?

This was going to be my original approach:

  • I only have access to a simple Perl based server, so I planned to use it as a tracker for all connected clients
  • A client can send two messages to the Perl script:
    1. List - get a list of all connected clients
    2. Remove [client] - When a connected client pings another client and finds it is not accessible, it will alert the server so it is removed. This makes sure the server does not need an active connection to the clients.
  • Every time a client sends any command to the Perl script, it will be added to the list of connected clients
  • All inter-client communication will go directly, the server only keeps track of who is connected, for more details each client must be asked.

Very simple approach. Should be stable, require little bandwidth, and also does not require me to be able to run anything else than standard Perl, which most hosts allow today.

What do you think of this approach? Could I set up a “punch through” from this scenario?

Thanks

You’re gonna love darkstar. It keeps track of all clients for you, and you can set up “listeners”, so that all clients see whatever another client sends.

https://games-darkstar.dev.java.net/
And the forums are right here on this same forum:
http://www.java-gaming.org/forums/index.php?board=52.0

Sounds great. However, do you think it would work for an action game like a real time racer? Also, how about Firewall problems?

I downloaded the game Stomping Grounds, which is using the service, but was disappointed to see it is was not only a turn based game, but it even was unable to find the Darkstar server. So, a bit worried if this thing works in real life…?

I could not find any working multiplayer action games using Darkstar, to validate the technology. Any pointers would be appreciated :slight_smile:

Absoltuely. Shawn’s racing game, Cosmic Racer, is a Darkstar app.

Since it does a star-netwowrk through the Darkstar back end, as long as the Darkstar backend isnt behind a firewall your fine. By definition a comemrcial deploymeny back end like you might go to for hosting of you game wont be.

There is a limitation in the implementation of the UDP today that makes firewalls a problem, but that is considered a bug and will be gone by commerical release.
I downloaded the game Stomping Grounds, which is using the service, but was disappointed to see it is was not only a turn based game, but it even was unable to find the Darkstar server. So, a bit worried if this thing works in real life…?

Shawn just released a tech demo for Cosmic Racer. You can talk to him about his expereinces. Im hoping to have him hosted out of our Alpha server when i have time to set that yp next week, after which you should be able to actually play it networked over the internet yourself.

Hi

in EA1 UDP is working, with the caveat that when the client is behind a NATed firewall, the client must send, to the server at least 1 message via udp before the server can successfully send any. This is because the NAT can’t work out what to do with the incomming UDP datagram untll the client has sent one outbound.

I get my client to send some message that the server ignores, then after that it’s all fine :slight_smile:

Endolf

Sounds good, I am very interested in his experiences.

So, if I understand correctly Darkstar gives Matchmaking for free, and then allow you to also connect directly client to client?

I think such a server-less approach is essential once the game gets going in my case, as my players will be in all parts of the world, and the lag of sending all data through Suns server might kill it…

I assume after the beta phase of Darkstar Sun will start charging for hosting. I am not really eager to put money into this as I am doing it just for my own education, but do you got any ideas if they will charge us, and roughly how much?

Oh, I guess the game mentioned above should be Cosmic Birdie, not Cosmic racer :wink:

The Full name is something enormous like “Cosmic Byride Auto-gyro Racer”, so it gets called many things.

Darkstar provides what looks like a virtual private LAN situation to the client API, but all communication flows in a star pattern through the server. This is imprortant to commercial games for security reasons.

If you really want true peer to peer either run your own introductions server or use JXTA.