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
|
<!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">File Transfer using UDT</font></h3>
<p>While you can always use regular UDT::send and UDT::recv to transfer a file, UDT provides a more convinient and optimized way for file transfer. An application can use UDT::sendfile
and UDT::recvfile directly. In addition, file transfer IO API and regular data IO API are orthogonal. E.g., the data stream sent out by UDT::sendfile does not necessarily require
UDT::recvfile to accept.</p>
<p>The sendfile and recvfile methods are blocking call and are not affected by UDT_SNDSYN, UDT_RCVSYN, UDT_SBDTIMEO, or UDT_RCVTIMEO. They always complete the call with the specified
size parameter for sending or receiving unless errors occur.</p>
<p>UDT uses C++ fstream for file IO.</p>
<p><strong>Example</strong>: send a file using UDT.</p>
<div class="code">
UDTSOCKET fhandle;<br>
...<br>
<br>
ifstream& ifs("largefile.dat");<br>
ifs.seekg(0, ios::end);<br>
streampos size = ifs.tellg();<br>
ifs.seekg(0, ios::beg);<br>
<br>
if (UDT::ERROR == UDT::sendfile(fhandle, ifs, 0, size))<br>
{<br>
cout << "sendfile: " << UDT::getlasterror().getErrorMessage();<br>
return 0;<br>
}
</div>
<p><strong>Example</strong>: Receive data into a file.</p>
<div class="code">
UDTSOCKET recver;<br>
...<br>
<br>
ofstream& ofs("largefile.dat");<br>
<br>
if (UDT::ERROR == UDT::recvfile(fhandle, ofs, 0, size))<br>
{<br>
cout << "recvfile: " << UDT::getlasterror().getErrorMessage();<br>
return 0;<br>
}
</div>
<p> </p>
</body>
</html>
|