File: t-file.htm

package info (click to toggle)
udt 4.11%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,096 kB
  • sloc: cpp: 10,426; makefile: 64
file content (55 lines) | stat: -rw-r--r-- 1,938 bytes parent folder | download | duplicates (4)
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">&nbsp;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>
&nbsp;&nbsp;cout << "sendfile: " << UDT::getlasterror().getErrorMessage();<br>
&nbsp;&nbsp;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>
&nbsp;&nbsp;cout << "recvfile: " << UDT::getlasterror().getErrorMessage();<br>
&nbsp;&nbsp;return 0;<br>
}
</div>

<p>&nbsp;</p>
</body>
</html>