🎉 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!

UDP normally, TCP for chat & data transfer..?

Started by
15 comments, last by civguy 23 years, 5 months ago
Should I open two connections in my game, one UDP and one TCP? For now I''ve just been using UDP. I would use UDP to send urgent messages that need low ping (player coordinates, shooting etc.) And TCP to send chat messages, world data (e.g. someone builds a new building in the world). And for downloading maps and new graphics from sever, I would use TCP. I''m just asking that does this make any sense? Do I get smaller bandwitch when using TCP (since it''s a stream and no headers are needed..? ) or should I just do everything with UDP, even file transfer?
Advertisement
TCP is a *logical* stream. The actual packets on the wire will still have headers - in fact TCP headers are bigger than UDP headers.

However, there''s nothing wrong with using TCP if that makes it easier for you. Especially for something like bulk file transfer where you''re would have to manually do all the resends/inorder recieves/etc that TCP does for you.

-Mike
First, UDP is a Connection-Less Protocol. Which is the good part of the protocal. So you don't need a dedicated port for it. All players can use one port on the server.

Now here's what's bad with UDP. It's Connection-Less. It's just told where to go and not how to get to it's distenation. This leads to large numbers of lost packets (I heard 50% lost from some people). You also get duplicated and out of order packets.

It can be used for any message but urgent ones? Not the best idea.

Here's how Yahn Bernier (Valve Software, Network Programmer on Half-Life) does what he calls Reliable UDP,

On the end of a message you tag on a sequence number. (example: The first UDP packet sent should have a sequence number of one, the next of two and so on.)

If you get a sequence number that is less then or equil to the last packet's sequence number. Then your duplicated or out of order. Discard that packet.
If the sequence number is greater then one more then the last number. You missed a packet. Ask for it again.
If the sequence number is one greater then the last sequence number then accept the packet.


------------------------------------------------------------
I wrote the best video game ever, then I woke up...

Grandus.Com

Edited by - Galileo430 on January 17, 2001 10:11:27 PM
------------------------------------------------------------I wrote the best video game ever, then I woke up...
> If the sequence number is greater then one more then the last number. You missed a packet. Ask for it again.

If this occurs a lot is it really quicker than TCP? How big should UDP packages be. For half life for example are you sending all player positions and actions at once or spreading them out in a bunch of smaller packages?
Personally, I don''t know much about this stuff but from Yahn Bernier''s Speach on Out of Game Networking (http://www.gamasutra.com/features/20000511/bernier_01.htm) here is what I know about UDP.

> If this occurs a lot is it really quicker than TCP?
I got no idea.

> How big should UDP packages be?
Valve Software now uses a 1450 byte maximum. (they used to use a 8K packet but they found that things on the internet would just throw them away.)

> For half life for example are you sending all player positions and actions at once or spreading them out in a bunch of smaller packages?
Half-Life might use TCP/IP for player positions. However I''m not sure. I guess you could do it all in one packet if you don''t go over that maximum size.
------------------------------------------------------------I wrote the best video game ever, then I woke up...
quote: Original post by Spyder

> If the sequence number is greater then one more then the last number. You missed a packet. Ask for it again.

If this occurs a lot is it really quicker than TCP? How big should UDP packages be. For half life for example are you sending all player positions and actions at once or spreading them out in a bunch of smaller packages?


I just know I''m going to offend someone here. Isn''t life sad?

The fact that you asked that question proves that you don''t know enough about TCP/UDP to actually know if these people are being helpful, or if they''re talking bullshit.

Go to the library. Read a few books about how internet protocols and network protocols work. Go to a search engine or 6, and try looking up some tutorials on the net - after all, I think it''s safe to assume the internet will have some information on internet protocls.

Eventually you''ll actually understand what''s going on.

Then not only will the answers make sense, you won''t even need to ask this question.

(It''s been asked over and over and over and over and over. People won''t stop asking it. When the world finally ends, people will still be desperately begging to be told if TCP or UDP is better. It''s a pity none of the people asking actually have the ability to understand anything.)

If you don''t understand what''s going on, how to you expect to actually make use of answers that you don''t understand?


No, I''m not calling you stupid. I''m simply pointing out that you actually need to learn this stuff for yourself if you ever want to actually write a real game that runs over the internet.

Alternatively, you can wait five minutes, until someone else asks the same pointless question.

(PS: an intelligent question to ask would be "can someone point me to some useful pages about how network protocols work?" That at least demonstrates a willingness to learn, and also that you realise it takes more than a 3 line post to explain TCP & UDP.)


I love it how AP gives the impression that he knows a lot, without actaully saying anything =)

If you are going to have a totally reliable UDP, then why not use TCP? After all, that''s what TCP was designed to do.

Or you could do a semi reliable UDP, so you just tack on say a 4 bit number at the end for the order and hope that it isn''t 16 packets out ever.

But as AP said, read about the protocols and learn for yourself, that will help a lot (I don''t know too much, except for what a bit of the MSDN told me )

Trying is the first step towards failure.
Trying is the first step towards failure.
quote:
I love it how AP gives the impression that he knows a lot, without actaully saying anything

I think he gave the best advice.

The advantage of using UDP is that you have more control over the packets; you have to implement reliablity etc yourself, but then you can turn it on&off on a per packet basis.

If you''re dl''ing a file, use established protocols like ftp or http1.1

If it''s your first networking program, you may want to use tcp just because there''s less issues involved to get data from one side to the other.

quote:
Valve Software now uses a 1450 byte maximum. (they used to use a 8K packet but they found that things on the internet would just throw them away.)

You''d think that "professionals" would have know that would happen. 50bytes for a saftey margin?

Of course, I just read about some dufus trying to use TCP for a "deterministic" networking scheme... seems like you''d use a routing protocol for stuff that needs to be routed, and a broadcast protocol for high (and consistent) performance.


You could look into directplay8, then you''d have a good idea of what a decent UDP based streamer should be capable of.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Thanks for the replies (except for that second AP, whose reply was quite useless).
I''ve already implemented an UDP winsock server/client system that takes care of packetloss, but I was just wondering if TCP uses less bandwitch for same amount of data. Hmm.. I''m not still sure about the answer though.

But I''ll check out what Directplay8 offers so I can implement those myself (or switch to DPlay8 if it seems fast enough).
AP, why don''t you answer the question instead of wasting bandwidth?

As for me, I just use DirectPlay and don''t worry about it.

This topic is closed to new replies.

Advertisement