The connect method connects to a server socket (in regular mode) or a peer socket (in rendezvous mode) to set up a UDT connection.
If success, 0 is returned; otherwise, UDT::ERROR is returned and specific error information can be retrieved by getlasterror.
Error Name | Error Code | Comment |
ENOSERVER | 1001 | server or peer socket does not exist, or there is no network connection. |
ECONNREJ | 1002 | the connection request was rejected by the peer. |
ESECFAIL | 1004 | connection was aborted due to possible attacks. |
ECONNSOCK | 5002 | the socket is not allowed to do a connectconnect call; it is either in listening state or has been already connected. |
EINVSOCK | 5004 | u is not a valid socket ID. |
ERDVUNBOUND | 5008 | the rendezvous mode has been enable, but bind was not called before connect. |
UDT is connection oriented, for both of its SOCK_STREAM and SOCK_DGRAM mode. connect must be called in order to set up a UDT connection. The name parameter is the address of the server or the peer side. In regular (default) client/server mode, the server side must has called bind and listen. In rendezvous mode, both sides must call bind and connect to each other at (approximately) the same time. Rendezvous connect may not be used for more than one connections on the same UDP port pair, in which case UDT_REUSEADDR may be set to false.
connect takes at least one round trip to finish. This may become a bottleneck if applications frequently connect and disconnect to the same address.
The blocking option does NOT affect the connect call, which is always blocked until the connection is either successfully set up or failed.
When connect fails, the UDT socket can still be used to connect again. However, if the socket was not bound before, it may be bound implicitly, as mentioned above, even if the connect fails. In addition, in the situation when the connect call fails, the UDT socket will not be automatically released, it is the application developer's responsibility to close the socket, if he/she does not need it anymore (e.g., to re-connect).