🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

TCP or UDP

Started by
9 comments, last by eNGIMa 22 years, 11 months ago
Recently a few of my friends and I have decided to make a worms style clone. It seems that the role of network programming has been thrust upoun me. What I would like to know is, what protocol should I use for the networking. Should I design my own reliable UDP protocol or should I try to use TCP. I have heard that TCP will slow down when a packet is dropped. So in that case could i turn somehow turn off the nagle algorithm and the delayed ACK algorithm ???
-=- Murphy was an optimist -=-
Advertisement
If you are designing for Windows and DirectX 8, I would recommend Direct Play. It lets you specify guaranteed only when you want it.


LostLogic
www.lostlogic.com
Author, Multiplayer Game Programming

LostLogicwww.GamerOutfit.comXBox 360 Community Games Reviews and NewsExisled - 2D/3D Shooter for XBox 360

Thanks LostLogic, im beginning to see more and more positive comments about direct play.

However there is one thing i forgot to mention in my previous post, the game is cross platform. Therefore i have decided to program in sockets as (i think?) it is pretty much cross platform. So im geussing that restricts me somewhat ...
-=- Murphy was an optimist -=-
If you are going cross platform (and can''t use DirectPlay) then your choice is UDP unless you have a turn based game. TCP/IP forces an acknowledgement for each packet that makes it unsuitable for real time action, especially on an unreliable Internet. I would suggest that you use UDP and a special packet that both client and server agree must be acknowledged. Use a timer on each side to verify that the packet has been received and put it in a separate thread so that the game can continue without it. That way other players and the server can continue to play. The client can try to send it three times -using the timer - if it fails then it has lost the server and drops out of the game. The server tries to acknowledge three times. The big danger would be a packet that requires acknowledgement gets sent to the server and there is no client to receive it. Hence you use a timer to force the packet to retransmit. After 3 tries without acknowledgement you drop the attempts, kill the client, broadcast to all other players that the client is gone and free the timer.
Thanks heaps for the reply. I figured that i would need to use UDP. Now for the rest of the game ...
-=- Murphy was an optimist -=-
Well. I have recently been developing a fast-action multiplayer 3d space shooter game and obviously chose to use UDP. But, for turn-based games, you can easily get away with pure TCP/IP connections. In fact, you can get away with a 2-3 second lag time (which worms does) in multiplayer games with no problem. Although, I didn''t use directplay, I created my own multi-threaded udp infrastructure, I am able to send the UDP packets as both reliable and unreliable. Unreliable are the speedy ''unreliable'' packets that we''ve all heard about. If they don''t reach their destination, who cares, if they make it late and out of order, kill em. Anyway, reliable sending is much like TCP/IP anyway, in fact, TCP is built off of UDP. If the reliable packet doesn''t reach the destination and the destination player doesn''t send back an ACK packet, then we send it again. Like I said, this will work for turn-based games. Because you are able to severely minimize your sending rate and the world state changes. It all comes down to how much sending you''re going to be doing, if you''re sending world updates about 10 per second, then TCP/IP is gonna flood and kill the experience for everyone (over the internet). I would always suggest building your own infrastructure from scratch with both reliable and unreliable support to get the invaluable knowledge and learn about what is actually going on. Then, you can weight the differences on your own, and tweak the actual code on the low-level. Anyone can use DP and call it their own, but all they *really* learned was the high-level network implementation. Consider it. It''s worth it.

~David M. Byttow
www.integralstudios.com
~David M. Byttowwww.integralstudios.com
Although, if you really just want to use DP, I would suggest reading Todd's book and really paying attention to the low-level socket sending part. This is invaluable when it comes to network programming and making decisions about how to implement certain features. It was a good book, I am just sad that it didn't really cover client-side prediction, extrapolation, etc. ie. All the tools and hacks that we use to attempt to 'overcome' the messiness of the internet and still make our games feel smooth. Maybe Multi-player Game Programming 2, huh Todd?

~David M. Byttow
www.integralstudios.com


Edited by - guitardave24 on July 21, 2001 10:41:54 AM
~David M. Byttowwww.integralstudios.com
Thanks for your ideas. But now i have another question, how reliable is UDP. Is it possible to send UDP packets to a loopback connection and be guaranteed the reception of it. Im guessing that there would be dropped packets when the computer is under high load as the buffer throws away some packets then.

Also when you send UDP packets across the internet, approximately what percentage of packets will be dropped (I saw in Unreal Tournament''s manual that it needs a packet loss rate of less than 5%)

At the moment im thinking that 95% of all game packets im sending arent really that important. So i''ll send the packets and hope they get there. When there are packets like a player has left the game ill send it reliably (thanks guitardave24 for the idea)

BTW i dont think that i will learn how to use DirectPlay as im always trying to learn the extremely low level stuff (doesnt mean that it''s always gonna work, but im trying )
-=- Murphy was an optimist -=-
Hi there.

I would say, for a game as simplistic as Worms, you would rarely get dropped packets with UDP. In my opinion, with two players only, using TCP would be fine for the speed of the gameplay.

My team wrote a set of home-made Winsock functions. Our send function, we could specify GUARANTEED packets, which would send TCP and then NOGUARANTEED would send as UDP.. So perhaps, you could use UDP for most of the packets, but send TCP for secured position packets like every few seconds.

I''m rambling.. but anyways, UDP would be fine for worms since there are only two players and sending x,y coordinates every frame.. no big deal... hope that helps..

-- Brian
quote: Original post by LostLogic
If you are designing for Windows and DirectX 8, I would recommend Direct Play. It lets you specify guaranteed only when you want it.


LostLogic
www.lostlogic.com
Author, Multiplayer Game Programming


But if DirectPlay works over TCP, how can it send non guaranteed packets?

Hi all.

This topic is closed to new replies.

Advertisement