I am quite familiar with TCP and UDP. I understand the process by which TCP establishes connections and other theoretical facts about TCP but when reading up about TCP hole punching for NAT Transversal, I have become stumped by how connect(), accept() and listen() is done in TCP. Is it a single or multiple sockets that are used for all this in TCP and is is this done the same way in UDP

  • 2
    2 sockets are used for this on each side. en.wikipedia.org/wiki/TCP_hole_punching
    – ott--
    Jan 30, 2013 at 16:47
  • connect(), accept(), and listen() are Berkeley socket API functions, and do not directly relate to the packets actually sent on the wire. Jan 30, 2013 at 20:50

1 Answer 1


Your question is about sockets, but I think you might be confused about what a NAT does.

For an incoming connection from a WAN computer to a NATted computer to work, the NAT has to be told, via a configuration mechanism, to forward packets from the WAN destined for a particular port to a port on one of the NATted computers.

For a connection originated on either side of the NAT, the NAT stores the packet's 5-tuple (source IP address, source port, protocol, destination IP address, destination port) and uses this information to determine where to forward packets

For packets destined for the WAN, the NAT rewrites the source address so that all responses are sent to it.

Because the NAT is acting like a transparent "man in the middle", all the socket functions work completely normally.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.