Advertisement

UDP vsTCP for games

Started by March 24, 2002 07:39 PM
40 comments, last by Tylon 21 years, 6 months ago
Avater,

Ok - since it''s been a while since I used DirectPlay, I decided to go have a look at the docs for 8.1...

It seems to me that you don''t even have a choice these days - you choose a "message category" where you specify reliability and whether or not the messages are sequential. Seems to me like DP will pick the protocol for you.

As for specifying the DPSEND_GUARANTEED (and this is only down in the Winsock level - not necessarily the level I was originally talking about) - using this will not necessarily work. It depends on the service you use. DirectPlay may indeed allow it, but it will likely use TCP for it.

Bob Scott
Bob ScottAI Designer/ProgrammerStainless Steel Studios
quote:
As for specifying the DPSEND_GUARANTEED (and this is only down in the Winsock level - not necessarily the level I was originally talking about) - using this will not necessarily work. It depends on the service you use. DirectPlay may indeed allow it, but it will likely use TCP for it.



Some quotes from the DirectXSDK docs

quote:
TCP/IP service provider
A service provider that uses Windows Sockets to communicate over the Internet or local area network (LAN), using the TCP/IP protocol. It uses User Datagram Protocol (UDP) packets for nonguaranteed messaging and TCP for guaranteed messaging. Using TCP/IP, a single computer can host multiple Microsoft® DirectPlay® sessions.


quote:
Reliable and Unreliable Messaging
Messages are sometimes lost in transit. Reliable messaging provides a guarantee that the target will receive every message. This type of messaging is required when data loss cannot be tolerated. Most reliable messaging schemes require the target to acknowledge receipt of each message. If the sender does not receive an acknowledgment within a specified timeout period, it resends the message. This process typically continues until the sender receives an acknowledgment, confirming that the message has arrived.

The DirectPlay protocol imposes a limit on the number of resend attempts. If no acknowledgment is received after a reasonable number of attempts, DirectPlay assumes that the connection has been lost, and closes it.

Unreliable messaging is the simplest form of network communication. It might be faster than reliable messaging because there is no guarantee that the message will be delivered to the target. The sender transmits the message. If the target does not receive the message, the sender will not transmit the message again, and the packet is lost.

Unreliable messaging is used primarily when speed or bandwidth is more important than an occasional lost message. For example, high-bandwidth streaming media applications often use unreliable messaging. They cannot afford to take up bandwidth with acknowledgments and retransmissions, nor can they wait for a lost message to be retransmitted. An occasional lost message normally has only a minor impact on quality, so it can be ignored.


So i think you can choose between UDP and TCP

[edited by - Avater on April 9, 2002 4:24:12 PM]
Advertisement
quote:
Original post by Ironside
I got the 64 socket limit info from <a href="http://www.gamedev.net/community/forums/topic.asp?topic_id=31426">THIS</a> thread. (last post) It may not be a factor for the Unix based implementation of sockets however.
Maybe you should spend some time learning before you post complete bullshit.

Using I/O completion ports, which is *the* recommended way of doing high-performance sockets on Windows NT, gives you really good performance.

Compared to the legacy *nix* model of creating a thread per client, I/O completion ports is a superior technology. You will see similar technologies becoming more common in the *nix as well as the Java world. NT has had if for years.

http://www.kegel.com/c10k.html#top
AP, you''re more than a year late.
Perhaps some kind moderator can close this thread?
UDP is only best if you are expecting large numbers of players on the same server, I''ve been working on an article about writing a simple UDP server/client system and it should be online here soon, but in the meantime feel free to ask anything you need to know - Suffice to say I fell in each and every pittrap there is to find in winsock, so I should be able to find and help you with anything related.
---Yesterday is history, tomorrow is a mystery, today is a gift and that's why it's called the present.
quote:
Original post by Beer Hunter
AP, you''re more than a year late.
Oh, sorry about that
I followed a link from somewhere else and got here, didn''t think about looking at the date.
Advertisement
quote:
UDP is only best if you are expecting large numbers of players on the same server

Uh... ok. Take out the "only" and you have a true statement. It''s interesting how most fast-action multiplayer games supporting 2-8 players use UDP. I personally don''t consider 2-8 to be "large numbers of players", so there must be another reason we use UDP in games. Maybe it''s because we have real-time data requirements. Not all games have such aggressive requirements of the network, but many do. Every multiplayer game I''ve worked on used UDP (although some use TCP for server-to-server communications).

Good luck on your article...
Quake(1) used TCP/IP networking. It was fine for LAN but on the internet it caused the kind of problems someone described, with the game occasionally getting "stuck" because of congestion, and when it cleared up there''d be a bunch of packets arriving at once, causing a sudden burst of movement. I believe QuakeWorld switched to UDP, and became a test bed for the tech eventually used in Quake2.
Heh btw the Quake 3 netcode is one of the worst I''ve ever seen. I can''t count all the "net congestion" messages I''ve received while playing that "game" on a fast DSL connection. So stop the bullshit and don''t quote Carmack''s when it''s about networking because that''s not what he does best imo.
UDP is usually used sue to the lower overhead and thus lower latency. But it's not guarenteed to get there.
TCP has a higher overhead and thus higher latency but it is guarenteed to get there.

As for which is best for a game, depends an awfull lot on the game.

I personally use both, anything not time sensitive that must absolutely get there is TCP, otherwise it's UDP simple.



[edited by - Soul on August 17, 2003 8:30:45 AM]

This topic is closed to new replies.

Advertisement