Well, I am using a C++ compiler, so I suppose that c++ lines are recommended, however, anytime I look for suggestions online, including this forum, I always find C lines squeezed here and there, since they work with this compiler too. I am for anything that works and runs smoothly.
With this being said, I am a bit confused by your code.
What I need is the actual bytes so I can send them via socket.
If I want to send only one image, this code works very well
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
char file_name[] = {"/home/Desktop/pics/pic.jpeg"};
ifstream stream(file_name, std::ios::in | std::ios::binary);
vector<char> imageDataVec((istreambuf_iterator<char>(stream)), istreambuf_iterator<char>());
cout << "Size: " << imageDataVec.size() << " bytes";
long converted_number = htonl(imageDataVec.size());
//send(new_socket, &converted_number, sizeof(converted_number), 0);
//send(new_socket, &imageDataVec, imageDataVec.size() , 0);
size_t sent{};
while (sent < imageDataVec.size()) {
int nbytes = send(new_socket, &imageDataVec[sent], imageDataVec.size() - sent, 0);
if (nbytes <= 0) {
std::clog << "error: while sending image\n";
break;
sent += nbytes;
cout<<nbytes<<"================"<<endl;
}
|
However, as you can see from the first line, I have to open the file as a 'char'.
Now, given what you wrote above, how to incorporate your code by replacing the first line?
Is it even possible to do it this way, or I have to rewrite my whole code?