1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
<!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>UDT <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>When UDT_RCVSYN is set to false, the <strong>connect</strong> call will return immediately and perform the actual connection setup at background. Applications may use epoll to wait for the connect to complete.</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 applications' responsibility to <strong>close</strong> the socket, if the socket is not needed 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>
|