UDT Tutorial: Transfer Files

Transfer Files

File transferring is a easy job in UDT. Note that a sent file is not necessarily received by recvfile, and vice versa.

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

In UDT, file transferring 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

CUDT sender;

...

 

ifstream& ifs("largefile.dat");

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

int size = ifs.tellg();

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

 

try

{

   sender->sendfile(ifs, 0, size);

}

catch (CUDTException e)

{

   // process error...

}

Example: receive data into a file using UDT

CUDT recver;

...

 

ofstream& ofs("largefile.dat");

 

try

{

   recver->recvfile(ofs, 0, size);

}

catch (CUDTException e)

{

   // process error...

}