?? t-data.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>Introduction</title>
<link rel="stylesheet" href="udtdoc.css" type="text/css" />
</head>
<body>
<div class="ref_head"> UDT Tutorial</div>
<h3><font color="#000080">Transfering Data using UDT</font></h3>
<p>This section describes using UDT to transfer data in streaming mode. This is exactly the same as using traditional BSD socket.</p>
<p>In streaming mode, neither a send or a recv call can guarantee that all data are sent or received in one call, because there is no boundary information in the data stream. Application
should use loops for both sending and receiving.</p>
<p><strong>Example: send a data block (buf, size) using UDT.</strong></p>
<div class="code">
int ssize = 0;<br>
int ss;<br>
while (ssize < size)<br>
{<br>
if (UDT::ERROR == (ss = UDT::send(usock, buf + ssize, size - ssize, 0)))<br>
{<br>
cout << "send:" << UDT::getlasterror().getErrorMessage() << endl;<br>
break;<br>
}<br>
<br>
ssize += ss;<br>
}
</div>
<p>Similarily, to receive data stream, the following example code can be used.</p>
<p><strong>Example: receive "size" of data into buffer "buf" </strong></p>
<div class="code">
int rsize = 0;<br>
int rs;<br>
while (rsize < size)<br>
{<br>
if (UDT::ERROR == (rs = UDT::recv(usock, buf + rsize, size - rsize, 0)))<br>
<br>
cout << "recv:" << UDT::getlasterror().getErrorMessage() << endl;<br>
break;<br>
}<br>
<br>
rsize += rs;<br>
}
</div>
<h5>Blocking vs. Non-blocking</h5>
<p>UDT supports both blocking and non-blocking mode. The above example demonstrated the blocking mode. In non-blocking mode, UDT::send and UDT::recv will return immediately if there is
no buffer available. Usually, non-blocking calls are used together with accept.</p>
<p>UDT also supports timed blocking IO with UDT_SNDTIMEO and UDT_RCVTIMEO. This is in the middle between complete blocking and complete non-blocking calls. Timed IO will block the
sending or receiving call for a limited period. This is sometimes useful if the application does not know if and when the peer side will send a message.</p>
<p> </p>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -