Multiplayer Network options(UDP, TCP.......)

cmreichl used Ask the Experts™
I'm working on a 3d multiplayer game.  Initially its basically gonna have the functionality of a 3d chat room with avatars and such.(There will be no collisions between avatars, so the main goal is how movement of other people look)

My question is this:
What are some of the prefered options to handle updating of position?

We will have a client server setup, with multiple clients connected to our server.  We have discussed trying to impliment a UDP Multicasting system, and have also debated a TCP/IP system.  Is it possible to do a UDP Multicast with an internet based game?(Meaning computers not on same subnet and such)  We are trying to avoid TCP/IP because of its huge network loads.  Please give me some thoughts, and your reasoning!  Just looking for a proof of concept, no code really.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
If it is purely a chat program, I think you could use TCP since the little extra latency won't hurt, plus the programming will be easier since TCP is reliable and you don't have to worry about dropped packets. If however you are planning for any "action" stuff, you should probably use UDP.

One problem with UDP is that it's not reliable; you will have to implement an option for reliable send yourself if needed. The trick however is not to use that all the time (else you could be using TCP anyway), but only for the really important stuff, while just hoping that enough of the UDP packets will come through for simple position updating etc.

As you probably know, you will also have to write some prediction code for the time between packets. The simplest thing is to not only send position in your update packets, but also velocity (and maybe even acceleration, depending on how far you want to take it) and use that vector to update the position every frame. There is no way you will be able to get a packet through every frame, and this will ensure that the object at least will keep moving in the correct general direction. When the next packet arrives, you simply update the correct position (possibly smoothing the transition out over a few frames), and if you're lucky nobody will notice. For more advanced stuff, start out with a google search on "dead reckoning".

Hope that helped a bit,

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial