UDT Tutorial: Transfer Files |
File transfer is trivial in UDT. Note that a sent file is not necessarily received by recvfile, and vice versa.
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 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.
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... } |
CUDT recver; ...
ofstream& ofs("largefile.dat");
try { recver->recvfile(ofs, 0, size); } catch (CUDTException e) { // process error... } |