UDT Tutorial |
While UDT was originally written for extremely high speed data transfer, there are many other potential benefits from this reliable UDP-based library. One particular usage is to setup reliable connections between machines behind firewalls, especially those NAT firewall. To meet this requirement, UDT has added the rendezvous connection setup support.
Traditional BSD socket setup process requires explicit server side and client side. To punch NAT firewalls, a common method is to use the SO_REUSEADDR socket option to open two sockets bound to the same port, one listens and the other connects. UDT provides the more convenient rendezvous connection setup, in which there is no server or client, and two users can connect to each other directly.
Inside the UDT implementation of the rendezvous connection setup, each UDT socket sends connection request to its peer side, and whoever receives the request will then send back response and set up the connection.
An example is shown below. Each UDT socket must bind to a known address and then try to connect to peer side's known address. After the connect call is returned, the UDT connection is set up.
Example: rendezvous connection setup
UDTSOCKET u; ... UDT::bind(u, &known_addr, sizeof(known_addr)); UDT::connect(u, &peer_addr, sizeof(peer_addr)); |
However, UDT does not support SO_REUSEADDR option. When both the user are behind firewalls and they talk to a known server for the peer address and port, a UDT socket can be set up first and connect to the server. After it retrieves the information about the peer side, it should then disconnect and start this rendezvous connection to the peer side.