Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  My UDP Protocol Wrapper  (Read 1592 times)
0 Members and 1 Guest are viewing this topic.
Offline Breadstick

Senior Newbie




while(true) me.doAction(Act ions.PWN_ALL);


« Posted 2004-08-02 01:49:26 »

I'm working on a reusable network layer for java games, and I have some questions about UDP.  TCP/IP support is finished, and now I'm just trying to design the UDP support before I start coding it.

I read that you shouldn't send UDP packets that contain small amounts of data in the "The Internet Sucks" article at:
http://www.gamasutra.com/features/19990903/lincroft_01.htm
because of uncompressed packet headers.  But that seems doesn't sound right... It seems like with many real-time multiplayer games, 'streaming' data is required.  Data consisting of small packets containing actions the other player(s) have taken, some sort of GameState, etc...  Whatever the method of updating the other player(s), the updates usually need to be quite frequent.  Any thoughts on his comment?

Also, I'm trying to design a method to ensure the arrival of packets when using UDP.  The only way I can think of is to send a response back when a packet is received.  But then you don't know if that response packet was received, therefore the response itself would require a response, and that response would require a response, and so on.  Also, this seems like it would create quite a bit of network latency.

Here's my project if you want to check it out:
http://gaming.cyntaks.com/projects/viewproject.php?project=RJNL

Breadstick
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #1 - Posted 2004-08-02 02:17:37 »

Quote

I read that you shouldn't send UDP packets that contain small amounts of data in the "The Internet Sucks" article because of uncompressed packet headers. But that seems doesn't sound right


That article sucks.

Anyway, the statement is not intrinsically wrong - you will hose bandwidth with small packets if you're not careful. A UDP packet has 22 bytes overhead, and if you send a single 4 byte number (java int) in each packet then you're wasting 3/4 of your b/w!

This is trivial to fix, though, you just batch your messages up to a configurable threshold. Set up a heuristic e.g.

"Whilst:
- I have less than 100 bytes of data to send
- the first byte of data came in less than 5 milliseconds ago
batch the data and don't send it yet"

This 5 ms wait would be invisible to players, on their minimum 30ms latency even for an almost directly-connected fast broadband connection - but it would spare you some b/w. Very significant if you have a lot of traffic.

But...it depends from game to game whether it matters enough to bother going to that length!

Quote

Also, I'm trying to design a method to ensure the arrival of packets when using UDP.


Welcome to the pain of why I strongly advise no-one to write their own protocol on top of UDP! Wink

Short answer: go read the internet RFC's that describe how TCP works. That includes all the detail you ever need on hwo to do retransmit.

Especially do NOT try and muck about thinking you're cleverer than the desingers of TCP - take it from me, you're not. Just implement what they did. Chances are, if you try and cut a corner, it'll come back to bite you on the ass some time in the future...

Finally, a warning: sometimes all the above advice is wrong. I had to make some assumptions about your project, and if I assumed wrong, then I could be telling you the wrong stuff. C.f. SWP who had a very unusual (as far as games are concerned Wink) protocol, and several standard assumptions no longer applied.

malloc will be first against the wall when the revolution comes...
Offline Breadstick

Senior Newbie




while(true) me.doAction(Act ions.PWN_ALL);


« Reply #2 - Posted 2004-08-02 04:24:43 »

Quote

Short answer: go read the internet RFC's that describe how TCP works. That includes all the detail you ever need on hwo to do retransmit.


That's interesting... It seems that the main point people use when claiming that UDP is faster than TCP/IP is the large overhead in TCP/IP because of how it ensures that lost packets are retransmited, and that packets arrive in the correct order.  If you must implement a system similar to TCP on top of UDP to ensure all your data is sent, can UDP really be faster when proper data transmission is important?  Tongue
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #3 - Posted 2004-08-02 10:49:52 »

Only fools claim that UDP is faster than TCP.

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #4 - Posted 2004-08-02 13:05:58 »

Quote
Only fools claim that UDP is faster than TCP.


Well said Smiley.

Breadstick, if you're not sure on this stuff, PLEASE read the massive great post that I went to the trouble of making sticky Wink. I assure you it's worth reading!

malloc will be first against the wall when the revolution comes...
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #5 - Posted 2004-08-05 13:18:24 »

Quote
Finally, a warning: sometimes all the above advice is wrong. I had to make some assumptions about your project, and if I assumed wrong, then I could be telling you the wrong stuff. C.f. SWP who had a very unusual (as far as games are concerned Wink) protocol, and several standard assumptions no longer applied.


Our media distribution tool "Copper" is now available based on this fast bulk data transfer using FEC and UDP.  The technique I was looking at is not suitable for the highly interactive game data, but would be suitable for streaming out things like models, level data, or game updates from the game server.

With a UDP-based FEC transmission protocol we are able to get much better utilization of the available bandwidth than TCP-based solutions such as FTP.

http://www.digital-rapids.com/Products_Copper.html

If you need reliable in-order delivery - that's what TCP already is, re-implementing it with UDP would be a complete waste.  Not to mention that all the routers between the game server and the clients already "know" TCP so they don't just blindly move IP packets.. they take TCP-specific stuff into consideration.

*edit* - I should say -"some" of the routers and equipment between the nodes would be TCP aware and do appropriate buffering and re-transmission without propagating the need to re-transmit back to the original sender.

Offline MGodehardt

Junior Member




why does the chicken cross the road?


« Reply #6 - Posted 2004-08-20 10:23:17 »

hint: TCP needs ACK, UDP not

depends on what you need, you have to decide wether TCP is better for your game or UDP fits in your game.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (11 views)
2014-07-29 18:09:19

Riven (8 views)
2014-07-29 18:08:52

Dwinin (8 views)
2014-07-29 10:59:34

E.R. Fleming (25 views)
2014-07-29 03:07:13

E.R. Fleming (10 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!