Making a client/server game with UDP?

Yet another networking question ;D
I’m finding networking tricky yet fun and interesting at the same time…

I’m trying to make a client/server architecture with UDP… is this kind of thing possible?
At the moment I am planning to have an id for each Client and the Client will send the id along with the packet…
I will also have an AcceptPacket which will be sent to the server when the Client starts… (although now that I think of it… This may get lost somewhere inbetween…)

Is there a better way of doing this?

What kind of game is it?

Well… its actually more for my game engine… My game engine uses client/server networking but I thought I might add UDP through the same way as I see the client/server way easy and kind of problem free…

Also… I tried making a simple multiplayer game with physics by having the server control the world but this created lag problems with TCP… so that is why I want to implement UDP…

I’ve written a really, really simple private UDP library for exactly this. Drop me a message if you’d like a copy. It returns Client objects with every received packet to the server, which also include unique identification numbers.

I would actually prefer to make this myself if that is alright… Can you please elaborate on how your library works?
Like how does it set up a connection with the UDP in such a way that you know that each client would have its own ID…

Identify clients by a combination of a) their source IP address/port and b) the client sends a random integer which it chooses when it first talks to the server. Chances of a clash are incredibly small.

Cas :slight_smile:

Am I just able to do it off the IP? Because from my understanding the IP is different on every computer…

Also how do you recreate an accept-like event? For when a client first connects with the server?

EDIT: so I can create a socket on the server for it to talk with…

Not necessarily different if they’re going through NAT router.

Client sends “hello, I’m 1234” message to server from 12.34.56.78:25000 and waits for ack. While it hasn’t got an ack it keeps sending the connection message periodically.
Server puts 12.34.56.78:25000,1234 as a key into a hashmap with some client state handler object as the value and sends an ack back.
From now on whenever a server receives a packet on its listening socket, it looks at the IP address and port that the packet came from, and then looks at the first int in the data. It then uses this to pass the message on to the appropriate client state handler in its hashmap.

Cas :slight_smile:

Thx, I’ll have a go implementing this into my engine…

Shouldn’t the server be choosing the identification key for the client? Say the client sends a key that is already taken, or doesn’t send one at all, things like that could cause the server to crash.