UDT Tutorial

Transfer files using UDT

Files can be sent or received at any time once the UDT connection is established. There is NO non-blocking mode for file sending or receiving, no matter how the UDT_SNDSYN and UDT_RCVSYN options are set.

In UDT, file transfer uses C++ fstream standard class to handle the files. The following examples show the usage of sendfile and recvfile.

Example: send a file using UDT

UDTSOCKET fhandle;

...

 

ifstream& ifs("largefile.dat");

ifs.seekg(0, ios::end);

int64_t 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 using UDT

UDTSOCKET recver;

...

 

ofstream& ofs("largefile.dat");

 

if (UDT::ERROR == UDT::recvfile(fhandle, ofs, 0, size))
{
   cout << "recvfile: " << UDT::getlasterror().getErrorMessage();
   return 0;
}

 

Note that a sent file is not necessarily received by recvfile, and vice versa. Also note that fstream in GCC 3.0 does NOT support large file (> 2GB) and please use other versions of GCC to compile UDT if you need large file support.