Good afternoon, I used the code at your address

Transmitting a file over a network through sockets "Transmitting a file over a network through sockets":

FILE *in = fopen("SocketServer.exe","rb"); while(!feof(in)) { b=fread(bufer,1,sizeof(bufer),in); size=ftell(in); printf("bytes read: %d, part:%d, pos: %ld \n",b,i,size); if(b!=0) send(current,bufer,b,0); i++; } 

but when I transmit, the jpeg is somehow distorted, it turns green, the pixels are shifted ... probably the carrier information is lost, as in the article by reference, they stint on it, is it possible here? Please help understand.

http://bytes.com/topic/c/answers/606052-socket-send-binary-jpeg

characterization finds 0 0 or ascii 0. Binary data, including jpegs, can be NULL much data to send (look at the return value of file.read for example) ... "

    1 answer 1

    I would have sinned here at feof (in). It is better to calculate the length of the file using

    FILE * f = fopen (...); if (f) {fseek (f, SEEK_END, 0); long size = ftell (f); fseek (f, SEEK_SET, 0); .... etc .... }

    and transmit byte portions until the final length is reached.

    • IMHO no. And feof (in) and such, for example, while ((b = fread (bufer, 1, sizeof (bufer), in))> 0) if (send (current, bufer, b, 0)! = B) fatal ("send file"); work properly. We must look for an error in other parts of the code. - avp pm