📄 connect.htm
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title> UDT Reference</title><link rel="stylesheet" href="udtdoc.css" type="text/css" /></head><body><div class="ref_head"> UDT Reference: Functions</div><h4 class="func_name"><strong>connect</strong></h4><p>The <b>connect</b> method connects to a server socket (in regular mode) or a peer socket (in rendezvous mode) to set up a UDT connection.</p><div class="code">int connect(<br /> UDTSOCKET <font color="#FFFFFF">u</font>,<br /> const struct sockaddr* <font color="#FFFFFF">name</font>,<br /> int* <font color="#FFFFFF">namelen</font><br />);</div><h5>Parameters</h5><dl> <dt><i>u</i></dt> <dd>[in] Descriptor identifying a socket.</dd> <dt><em>name</em></dt> <dd>[out] Address of the server or the peer socket.</dd> <dt><em>namelen</em></dt> <dd>[out] Length of the <i>name</i> structure.</dd></dl><h5>Return Value</h5><p>If success, 0 is returned; otherwise, UDT::ERROR is returned and specific error information can be retrieved by <a href="error.htm">getlasterror</a>.</p><table width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#CCCCCC"> <tr> <td width="17%" class="table_headline"><strong>Error Name</strong></td> <td width="17%" class="table_headline"><strong>Error Code</strong></td> <td width="83%" class="table_headline"><strong>Comment</strong></td> </tr> <tr> <td>ENOSERVER</td> <td>1001</td> <td>server or peer socket does not exist, or there is no network connection.</td> </tr> <tr> <td>ECONNREJ</td> <td>1002</td> <td>the connection request was rejected by the peer.</td> </tr> <tr> <td>ESECFAIL</td> <td>1004</td> <td>connection was aborted due to possible attacks.</td> </tr> <tr> <td>ECONNSOCK</td> <td>5002</td> <td>the socket is not allowed to do a <strong>connect</strong>connect call; it is either in listening state or has been already connected.</td> </tr> <tr> <td>EINVSOCK</td> <td>5004</td> <td><i>u</i> is not a valid socket ID.</td> </tr> <tr> <td>ERDVUNBOUND</td> <td>5008</td> <td>the rendezvous mode has been enable, but <strong>bind</strong> was not called before <strong>connect</strong>.</td> </tr></table><h5>Description</h5><p>UDT is connection oriented, for both of its SOCK_STREAM and SOCK_DGRAM mode. <strong>connect</strong> must be called in order to set up a UDT connection. The <i>name</i> parameter is the address of the server or the peer side. In regular (default) client/server mode, the server side must has called <strong>bind</strong> and <strong>listen</strong>. In rendezvous mode, both sides must call <strong>bind</strong> and connect to each other at (approximately) the same time. Rendezvous <strong>connect</strong> 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. </p><p><strong>connect</strong> takes at least one round trip to finish. This may become a bottleneck if applications frequently connect and disconnect to the same address.</p><p>The blocking option does NOT affect the <strong>connect</strong> call, which is always blocked until the connection is either successfully set up or failed.</p><p>When <strong>connect</strong> 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 <strong>connect</strong> fails. In addition, in the situation when the <strong>connect</strong> call fails, the UDT socket will not be automatically released, it is the application developer's responsibility to <strong>close</strong> the socket, if he/she does not need it anymore (e.g., to re-connect).</p><h5>See Also</h5><p><strong><a href="listen.htm">listen</a>, <a href="bind.htm">bind</a></strong></p><p> </p></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -