javanetwork-programmingudpmultiplayergame-maker-studio-1.4

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


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 ?


Solution

  • 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.