Socket send binary data error

Dec 16, 2011 at 12:19pm
Hi,

I'm implementing socket on c++, but when i transfer some binary data from one side to another it dont works well.
If i send a file with 279mb on the other side it's with 300mb.
I think it's some kind of trash on the memory sequence, but i dont know how to send the correct size.

Here is the code:
Send ->
if(myfile.is_open()){
while(!myfile.eof()){
// getline(myfile, line);
myfile.read(echoString, 1024);
sock.send(echoString, sizeof(echoString));
}

Receive ->
while ((recvMsgSize = sock->recv(echoBuffer, RCVBUFSIZE)) > 0) { // Zero means
// end of transmission
printf("%.*s", recvMsgSize, echoBuffer);
// Echo message back to client
//sock->send(echoBuffer, recvMsgSize);
}

Someone can help me?
Dec 16, 2011 at 3:15pm
You are reading (up to) 1024 bytes but it may only read a smaller amount. If you were to use readsome() instead of read() the return value would be the actual number of characters, which you could then pass to the send() function.
Topic archived. No new replies allowed.