Advertisement

Network Programming with UDP examples

Started by July 07, 2002 09:29 PM
18 comments, last by Coreyh 22 years, 6 months ago
Where are some examples of good UDP game programming? I have Unix Network Programming but it doesn''t talk about it in a gaming sense. I was wondering about security and dealing over overflows/DOS? I searched newgroups and it seemed like that was a issue. Older version of MAngband used UDP but from reading the mailing list it sounded like when they switched to TCP it worked better. I''m not sure if that ment the UDP code wasn''t well written or the game just wasn''t the right kind. All my testing has been local so far. Is there a good example of faking packet lost and out of order packets locally? Thanks wierdd@hotmail.com www.ipeg.com/~rlfc
kdIXfA.gamedev.10.coreyh@xoxy.netwww.ipeg.com/~rlfc
You could put a network loss etc. simulation into your program fairly easily. Just randomly not send, or delay packets etc. (not sending would be very simple, delay maybe a bit more work). I am sure there are programs out there to disrupt your network, i know there is one that comes with DPlay, but i''m not sure if it only affects DPlay connections...
Advertisement
Why doya wanna use UDP to code a game ?

I mean..
UDP is very comfortable for Broadcast-/Network testing Apps

The main advatage of UDP is that you can send Packets to anyone at anytime without caring of connections. But what good is this in a game ?!?
Do ya wanna code a Peer-To-Peer Game ?

Any Game i could think of would be best realised with a Server-Client-Architecture (and TCP is best for this, believe me!)

It is not possible to use UDP on the Internet, ya know !
AP #2: i think that just reading your post made us all stupider...
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
yeah seriously...that response from AP was frightening in the sheer scope of ignorance.

I''ve been working on my own network layer that uses a hybrid system.. serialized packets going over both a UDP and a TCP connection..TCP maintains the game connection and transfers packets critical to the game state, UDP sending just the simple delta updates etc that are non essential. Finding the information on how to do this, however, has been a nightmare.

The best information that I have found has been Beej''s guide to network programming...there''s a small section in there on UDP client server stuff, and if you read it all you get the gist of what has to be done/modified to work properly. Interestingly, and also quite useful to my whole server architecture, he also has a guide on unix interprocess communication (IPC) that is excellent. They are located at
http://www.ecst.csuchico.edu/~beej/guide

Good luck
Texlan
Texlan
Thanks for the help. Unix Network Programming covered the same things as that guide. The references look helpful though. I''ve having trouble finding advanced infomation about game network programming also. Unix Network Programming was quite a bit better then that guide if you are ever looking for a book. Doesn''t talk about games though.

I''m still wondering about security when using udp. I''m sure I can get something simple and reliable working but I''m not sure how to handle fake packets or my socket buffer being overflowed. I only know about those issues from reading a old thread in a newsgroup.

I''ll spend so more time trying to find information then just work on the simple and reliable way I can imagine getting it done. I''ll just have to change it later but I''ll still learn from it.


wierdd@hotmail.com
www.ipeg.com/~rlfc
kdIXfA.gamedev.10.coreyh@xoxy.netwww.ipeg.com/~rlfc
Advertisement
Hey Coreyh,

Unix Network Programming has a lot of information about denial of service and other security concerns. Since network security isn't a game specific topic, you might consider looking at amazon or barnes and noble and do a search for network security. You will probably find a ton of references there. (and of course check for free online references with google before buying anything from the stores...)

Also, the book Advanced 3D Game Programming has a good chapter on reliable UDP for games. It provides a very basic sample implementation as well.

[edited by - fingh on July 13, 2002 1:05:03 PM]
"I''m still wondering about security when using udp. I''m sure I can get something simple and reliable working but I''m not sure how to handle fake packets or my socket buffer being overflowed. I only know about those issues from reading a old thread in a newsgroup."

I have been seeing quite a bit of people asking about buffer overflows on here lately, but I am not sure they really understand what they are. Buffer overflows can be avoided by simply making sure you don''t fill any fixed-length buffers with data that is larger than the max amount. Ie. A string setup to handle 10 bytes, should not ever be stuffed with more than 10, or a buffer overflow will occur. Simply write checks in your code to make sure that you don''t overflow the buffers, and you will be fine.

As for the security, there are many steps you could take to deal with this, but in the end it really depends on how far you would like to go. You could build a hash string, serialize, or even encrypt your packets, but the more you add, the more code that gets executed on each network call, which means more lag in the end on lower-end machines. Some games don''t need much security at all, as there is such a thing as Security Through Obscurity. Design your protocol well enough, and handle packets that just don''t "fit", and you should be fine. Then again, there are different models that should be followed depending on your game type, peer-to-peer, client-server, MMORPG, etc.

Sorry, its late, otherwise I would have gone into more detail.

DS
quote:

I have been seeing quite a bit of people asking about buffer overflows on here lately, but I am not sure they really understand what they are. Buffer overflows can be avoided by simply making sure you don''t fill any fixed-length buffers with data that is larger than the max amount. Ie. A string setup to handle 10 bytes, should not ever be stuffed with more than 10, or a buffer overflow will occur. Simply write checks in your code to make sure that you don''t overflow the buffers, and you will be fine.



AP, I believe the buffer overflows they are talking about are in reference to the low level UDP receive buffers, not static arrays in their application code.
Of course as long as the OS works properly (...) this shouldn''t happen, if the buffer gets full new packets should simply be discarded. So i think, as far as guarding against buffer overflows in your program is concerned, it is actually this overflowing the static array of your receive buffer that is the security problem. I think

This topic is closed to new replies.

Advertisement