UDT Reference: Functions

#### connect

The connect method connects to a server socket (in regular mode) or a peer socket (in rendezvous mode) to set up a UDT connection.

int connect(
UDTSOCKET u,
const struct sockaddr* name,
int* namelen
);

##### Parameters

u
  [in] Descriptor identifying a socket.
name
  [out] Address of the server or the peer socket.
namelen
  [out] Length of the name structure.

##### Return Value

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.

##### Description

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.

UDT connect takes at least one round trip to finish. This may become a bottleneck if applications frequently connect and disconnect to the same address.

When UDT_RCVSYN is set to false, the connect call will return immediately and perform the actual connection setup at background. Applications may use epoll to wait for the connect to complete.

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 applications' responsibility to close the socket, if the socket is not needed anymore (e.g., to re-connect).

##### See Also

listen, bind