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