UDT Tutorial

### File Transfer using UDT

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.

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.

UDT uses C++ fstream for file IO.

Example: send a file using UDT.

UDTSOCKET fhandle;
...
ifstream& ifs("largefile.dat");
ifs.seekg(0, ios::end);
streampos size = ifs.tellg();
ifs.seekg(0, ios::beg);
if (UDT::ERROR == UDT::sendfile(fhandle, ifs, 0, size))
{
cout << "sendfile: " << UDT::getlasterror().getErrorMessage();
return 0;
}

Example: Receive data into a file.

UDTSOCKET recver;
...
ofstream& ofs("largefile.dat");
if (UDT::ERROR == UDT::recvfile(fhandle, ofs, 0, size))
{
cout << "recvfile: " << UDT::getlasterror().getErrorMessage();
return 0;
}