i have created server and client to communication. Client sends binary data of image then server receives it and writes to file. I have pasted necessary code below.
std::stringstream binStr;
bytes_received = recv(new_sd, &binStr, sizeof(binStr) ,0);
std::cout << binStr << std::endl;
char buff[1024*1024];
std::string image;
while (!binStr.eof())
{
binStr.read(buff, sizeof (buff));
image.append(buff, binStr.gcount());
}
int id = 1;
std::stringstream ss2;
ss2 << id;
std::string str2 = ss2.str();
std::ofstream img(str2.c_str(),std::ios::binary);
std::cout << image.c_str() << std::endl;
img.write(image.c_str(), image.length());
this code creates file with name as id , but its an empty file. How can i fix it?