Hi all,
I have a small problem.
I am trying to download a JPG image from a server using C socket programming.
I use the following to "recv" the byte stream and store it into a file I call "test.jpg".
The problem is, after I try to open the test.jpg, it gives me a "Windows cannot open this image as it appears to be damaged, corrupted, or is too large" message.
If I use fopen to create the file though, I'm able to open the image in a select few image browser softwares, but not in the Windows Photo Viewer.
Can anybody point out what I am doing wrong? Is it possible to transfer an image over sockets like this?
Thanks,
Sid
I have a small problem.
I am trying to download a JPG image from a server using C socket programming.
I use the following to "recv" the byte stream and store it into a file I call "test.jpg".
Code:
int fp = open("c:\\test.jpg", O_RDWR|O_CREAT);
/* set up the socket connection */
while(recvdata != 0){
recvdata = recv(sockfd, buff, 100, 0);
if(recvdata != 0){
write(fp, buff, recvdata);
}
}
If I use fopen to create the file though, I'm able to open the image in a select few image browser softwares, but not in the Windows Photo Viewer.
Can anybody point out what I am doing wrong? Is it possible to transfer an image over sockets like this?
Thanks,
Sid
Comment