1

I'm trying to develop a game with using java server and game maker studio client. I've written some basic connection code and it works fine in my local network. But when I host the server and try to connect my client gets the ID assigned by server which sent through TCP but it does not receive any commands sent by UDP protocol. How server can't establish connection over UDP while it can over TCP. I heard I need UDP hole punching. But once I'v written the server with game makers studio networking functions and UDP was able to establish connection with same configurations on the server. So they are using hole punching in their built-in functions ? If I need to implement hole punching instead should I use TCP only or I should learn hole punching for any cost ?

brainoverflow98
  • 1,138
  • 11
  • 28

1 Answers1

3

There are quite a few questions here so I'll try to break them apart piece by piece. First of all...

Does NAT block UDP packets coming from a server connected using TCP?

Yes. Just because the NAT has established a TCP connection between two machines does not mean it will automatically forward UDP packets as well.

How server can't establish connection over UDP while it can over TCP?

TCP is a connection oriented protocol while UDP is a connectionless protocol, so there is technically no such thing as a "UDP connection". When two computers communicate via UDP they simply exchange UDP packets back and forth and the "connection" is implied (or managed at a higher level), rather than spelled out by the UDP protocol itself.

I heard I need UDP hole punching... If I need to implement hole punching instead should I use TCP only or I should learn hole punching for any cost ?

UDP hole punching is one possibility but it is complicated and not 100% guaranteed that all NATs will be compatible. Instead, you could build your game using just TCP, then once it is working and deployed, experiment with more advanced communication channels like UDP hole punching or WebRTC Data Channels.

v1bri
  • 1,398
  • 8
  • 13
  • You are awesome thank you really much ! A few more questions since I think you are experienced in this field :) Can I trick UDP to make it act like a connection oriented protocol ? What other online fps games use in their networking because I am pretty sure they use UDP since fps games requires speed they also use hole punching ? – brainoverflow98 Nov 09 '17 at 23:15
  • Sure thanks. It is actually the process of UDP hole punching that "tells" a compatible NAT that you want to set up a "UDP connection". If hole punching is successful, the NAT will internally remember to forward UDP packets back and forth. Not all NATs support hole punching though. Refer to [Section 3](http://www.brynosaurus.com/pub/net/p2pnat/) for a description of how UDP hole punching works. You are correct, many games use UDP however it will introduce [other problems](https://softwareengineering.stackexchange.com/questions/193745/udp-order-of-packets-with-direct-connection). Good luck. – v1bri Nov 09 '17 at 23:52