Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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  
  Getting UDP through NAT/firewalls/whatever...  (Read 1707 times)
0 Members and 1 Guest are viewing this topic.
Offline swpalmer

JGO Coder

Exp: 12 years

Where's the Kaboom?

« Posted 2004-01-08 21:25:29 »

I came across this today on a Mac gaming mail list.  The author is Wade Williams a Systems Engineer at Cisco Systems.  I'm going to assume that makes him an authority on the matter Smiley
Reproduced without permission (it was on a public email list Smiley)
     From:         ******
     Subject:       Re: Getting UDP through NAT/firewalls/whatever for a game.
     Date:       January 8, 2004 5:38:27 PM EST

In a complete example, what would happen is:

1)  Client logs in with TCP connection to pass username/password, etc.  Client also tells server what port to send an unsolicited UDP packet on.

2)  Server tries unsolicited UDP connection.  If it works, it uses that for this client.

3)  If client does not receive unsolicited UDP packet in a specified amount of time, it starts sending UDP messages to the server (in essence, a UDP "ping") in order to allow the now solicited messages from the server to return.  As someone suggested, one every 15 seconds or so would probably work fine.

4)  If after sending the UDP messages to the client, the server is unable to get an acknowledgment from the client that its UDP messages are being received, the server begins sending over the TCP connection.

Now, with all that said, the code to send the UDP ping doesn't really add any significant overhead, so you're probably better off by simplifying things and leaving out steps 1 and 2, since they're unlikely to work in a large number of scenarios.

Note that if there's any way possible, you *should* provide the ability to fall back to TCP only.  This will work a lot better than you think.  It works great for our multiplayer flight sim.  UDP should be used if possible, but you'll be surprised at how well TCP works.


"solicited UDP" being defined as a process where the client repeatedly sends UDP packets to the server (above it says 1 every 15 seconds) so that the NAT/firewall keeps a mapping between the client and the port it uses on the other side.

Many of you are likely aware of this technique, but I figured I would post it for newbies.  I probably should put it on the Wiki, but first I post it here for comments.

Offline Jeff

JGO Coder

Got any cats?

« Reply #1 - Posted 2004-01-08 22:37:07 »

Nice, thanks SWP!

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!
Pages: [1]
  ignore  |  Print  

EgonOlsen (61 views)
2018-06-10 19:43:48

EgonOlsen (42 views)
2018-06-10 19:43:44

EgonOlsen (61 views)
2018-06-10 19:43:20

DesertCoockie (241 views)
2018-05-13 18:23:11

nelsongames (142 views)
2018-04-24 18:15:36

nelsongames (141 views)
2018-04-24 18:14:32

ivj94 (883 views)
2018-03-24 14:47:39

ivj94 (144 views)
2018-03-24 14:46:31

ivj94 (795 views)
2018-03-24 14:43:53

Solater (159 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!