我想使用套接字将二进制文件从客户端发送到服务器。 这是我读取文件的代码:
size_t buffer_size = 512;
std::fstream myfile;
myfile.open(filePath[i], std::ios::in | std::ios::out |
std::ios::binary);
std::vector<char> myBuffer(512);
std::ostream_iterator<char> osIt(std::cout);
//std::ifstream myfile(filePath[i]);
while (myfile)
{
myfile.read(&myBuffer.front(), buffer_size);
if (!myfile)
{
myBuffer.resize(myfile.gcount());
}
std::string msg(myBuffer.begin(), myBuffer.end());
doLog("sending message");
sout << locker << "\n " << msg.c_str() << unlocker;
q_.enQ(msg);
::Sleep(10 * id()); // sleep time increases with each
addition Sender
if (pSt->status() == "bad")
break;
}
我正在使用BLOCKING队列,并且还通过bloxk读取文件块,每个块大小为512.
这是我在服务器端保存文件的代码:
msg = q_.deQ();
std::ofstream myStream;
myStream.open("../Test/Client1/Received_Files/darkKnight.jpeg",
std::ios::out | std::ios::app | std::ios::binary);
myStream << msg;
if (msg == "stop\n"){
myStream.close();
}
我无法打开创建的输出图像。
答案 0 :(得分:0)