jared888
Senior Newbie 
Eat your own shorts. Leave mine alone.
|
 |
«
Posted
2004-04-14 22:44:56 » |
|
Hey,
If I want fast AND reliable, do I use UDP and write my own error/datagram tracking into my app?
|
Beware the rabbit of the mind, for it gnaweth on the carrot of the soul.
|
|
|
blahblahblahh
|
 |
«
Reply #1 - Posted
2004-04-14 23:10:57 » |
|
No. But if you want reliable and out-of-order delivery, then yes.
Whether or not it's "faster" depends upon the exact traffic patterns of your game (in general, it will often be slower).
And don't bother writing your own unless you're trying to get a job in writing network protocols. There's too many free ones for it to be worth re-inventing the wheel (would you write your own software 3D renderer without OpenGL? Obviously a few would, but usually only those wanting to prove their abilities at 3D maths)
|
malloc will be first against the wall when the revolution comes...
|
|
|
jared888
Senior Newbie 
Eat your own shorts. Leave mine alone.
|
 |
«
Reply #2 - Posted
2004-04-15 11:37:05 » |
|
I don't actually want to re-write networking code. I would use the existing sockets classes to build my communications between game components (I have a 3 tier plan).
So, what you are sayting, is that if I want stuff to be reliably delivered in order, I want to use TCP, and it won't be significantly slower than UDP?
Thanks!
|
Beware the rabbit of the mind, for it gnaweth on the carrot of the soul.
|
|
|
Games published by our own members! Check 'em out!
|
|
Herkules
|
 |
«
Reply #3 - Posted
2004-04-15 11:46:34 » |
|
For sure not slower than a protocol on top of UDP with these features.
|
|
|
|
jared888
Senior Newbie 
Eat your own shorts. Leave mine alone.
|
 |
«
Reply #4 - Posted
2004-04-15 17:57:05 » |
|
Thanks all, y'all just made my life a heckuva lot easier!
|
Beware the rabbit of the mind, for it gnaweth on the carrot of the soul.
|
|
|
Matei
Senior Newbie 
';..;'
|
 |
«
Reply #5 - Posted
2004-05-05 23:33:31 » |
|
It depends a lot on what kind of game you make. After wondering about TCP vs UDP myself, I was quite surprised to find out that virtually all MMORPG games, for example, use TCP. UDP is only for when you need very fast reactions, perhaps in a shooter game.
|
|
|
|
|
blahblahblahh
|
 |
«
Reply #6 - Posted
2004-05-06 01:01:56 » |
|
It depends a lot on what kind of game you make. After wondering about TCP vs UDP myself, I was quite surprised to find out that virtually all MMORPG games, for example, use TCP. UDP is only for when you need very fast reactions, perhaps in a shooter game. If you're going to make a statement like that you should list the games you're citing.
|
malloc will be first against the wall when the revolution comes...
|
|
|
endolf
|
 |
«
Reply #7 - Posted
2004-05-06 08:53:38 » |
|
Ultima online uses TCP, but Earth and Beyond uses both. UO of course is just point and click for movement, whilst Earth and Beyond isn't. Dark age of Camelot also uses UDP and again is not just point and click for movement. It would *seem* that even some of the newer MMORPGs are using UDP for some parts of the game play. Just for interests sake  Endolf
|
|
|
|
aldacron
Senior Member    Medals: 4
Java games rock!
|
 |
«
Reply #8 - Posted
2004-05-06 11:19:02 » |
|
Dark age of Camelot also uses UDP and again is not just point and click for movement. Actually DAOC uses both TCP and UDP. UDP handles all of the positional updates, spawn notifications, etc...
|
|
|
|
|
endolf
|
 |
«
Reply #9 - Posted
2004-05-06 11:26:21 » |
|
The all use TCP for something, usually login/updates and a few other things, I was only mentioning the gameplay/movement aspects, as I assumed TCP for certain things was a given  Endolf
|
|
|
|
Games published by our own members! Check 'em out!
|
|
blahblahblahh
|
 |
«
Reply #10 - Posted
2004-05-06 11:31:00 » |
|
The all use TCP for something, usually login/updates and a few other things, I was only mentioning the gameplay/movement aspects, as I assumed TCP for certain things was a given  Endolf Exactly. My guess on reading the "most use TCP" statement was that is what the poster was probably referring to, and that they hadn't checked their facts fully (e.g. had just seen "game X uses TCP" and assumed that meant it didn't use UDP and that it used TCP for something other than OOB data). Hence the request for a list of games, so we can check their facts.
|
malloc will be first against the wall when the revolution comes...
|
|
|
crystalsquid
Junior Member  
... Boing ...
|
 |
«
Reply #11 - Posted
2004-05-06 12:57:55 » |
|
For MMORPG in-game messages, the main performance issue with TCP is the socket-per-client overhead on the server, and can impact performance (using a thread per socket and 1000+ clients is a lot of thread switching).
Another aside is that each socket will perform its own throttling, which is good for clients, but means its trickier to throttle the whole server when the server output stream bandwidth is too large.
Building a TCP stack on UDP eliminates the thread overhead and socket management, but you really should implement a SACK-TCP per-client, and add some global throttling to this. Its a fair amount of work but will save you some significant proportion of server processing when you get it right. You should refer to the relevant RFC docs to get it right - there is a lot of freely available information there that would take you months to work out by yourself, + important algorythms to use so that you don't start knocking routers over when things start going wrong (which they will do).
My own implementation also uses a reduced header of around 8 bytes instead of the 20-ish of TCP. For 1000 clients and 4 msg's per second this can save you 100kbs!
To summarize - for (at a guess) 50 clients or less, the standard TCP is MUCH easier to implement, less prone to errors, and not too much overhead. If your client numbers is reaching over 500+, you should probably consider your own UDP stack - or powerful (& expensive) multiprocessor servers / a server farm. You can beat TCP performance, but only in the realms that TCP wasn't originally intended for, and only with a lot of work.
- Dom
|
|
|
|
|
endolf
|
 |
«
Reply #12 - Posted
2004-05-06 13:10:20 » |
|
For MMORPG in-game messages, the main performance issue with TCP is the socket-per-client overhead on the server, and can impact performance (using a thread per socket and 1000+ clients is a lot of thread switching). Thats what NIO is for, no more do you need a thread per socket. It *was* a problem with the old Java IO and TCP, under C you've always had the selectors like in NIO anyway. Endolf
|
|
|
|
Gambit
Senior Newbie 
Java games rock!
|
 |
«
Reply #13 - Posted
2004-05-06 13:49:45 » |
|
Dom could you give more details or some links about building TCP like protocol on top of UDP?
Cheers, Gambit
|
|
|
|
|
crystalsquid
Junior Member  
... Boing ...
|
 |
«
Reply #14 - Posted
2004-05-06 19:53:53 » |
|
Endolf: You're right - Due to various reasons I always end up thinking of Java 1.1 as that is our target platform most of the time. I haven't looked into NIO myself  On Windows (C++) you need to use IOCompletionPorts to handle all the sockets instead - which is a big pain that I couldn't be bothered to wade thorugh... Not sure what Linux is like for 1000+ TCP sockets, but now I have my UDP library I don't need toknow  Gambit: Useful things to look at: ENet: http://enet.cubik.org/ A good starting point (in C though). It doesn't do Selective ACKs (which is a must) but does include a few other essential TCP features such as exponential back-offs, and the receiver window system. And some googled stuff: RFC2581: Congestion Control http://www.zvon.org/tmRFC/RFC2581/Output/chapter3.htmlThe basic algorithms you need to consider. RFC 3517: A Conservative SACK based loss-recovery system http://community.roxen.com/developers/idocs/rfc/rfc3517.htmlA very good algorithmic description of using SACKs. It also has a few references to other useful RFC's http://www.eventhelix.com/RealtimeMantra/Networking/TCP_Fast_Retransmit_and_Recovery.pdfA nice descriptive 'flow' of communications using fast retransmits & SACKs. These were pulled from my old favourites when I was writing my network layer, and I found them to be very useful. Hope this helps, - Dom
|
|
|
|
|
Gambit
Senior Newbie 
Java games rock!
|
 |
«
Reply #15 - Posted
2004-05-07 06:51:49 » |
|
THX Dom!
Cheers, Gambit
|
|
|
|
|
aldacron
Senior Member    Medals: 4
Java games rock!
|
 |
«
Reply #16 - Posted
2004-05-07 16:39:44 » |
|
Endolf: On Windows (C++) you need to use IOCompletionPorts to handle all the sockets instead - which is a big pain that I couldn't be bothered to wade thorugh... Actually, you don't *need* to use IOC on Windows. There are several (at least 4) models available. Besides, IOC does not work on Win9x kernels. Aside from select, the simplest model to use is AsyncSelect, in which socket events are handled via Windows messages. It's also more efficient than select. I've always wondered which model NIO uses under the hood on Windows.
|
|
|
|
|
|