Home > Software engineering >  Use UDP send and receive TXT file normal other wouldn't open
Use UDP send and receive TXT file normal other wouldn't open

Time:10-06


Restaurant description, why use UDP send and receive TXT file is normal, and the other can't open?

Sender:
If (fopen_s (& amp; Fp, "C: \ \ picture. JPG", "rb +")!=NULL)////"rb" binary file in a read-only way open
{
MessageBox (" mysend. TXT open failure!!!!! \n");
fclose(fp);
}
//get file size
Fseek (fp, 0, SEEK_END);
Filelen=ftell (fp);
Fseek (fp, 0, SEEK_SET);//fseek (fp, 0, 0);//move the file pointer back to the fp first

Char buf [BUFFER_SIZE]={0};

While (1)
{
Memset (buf, 0, BUFFER_SIZE);
Fread_s (buf, BUFFER_SIZE, 1, BUFFER_SIZE, fp);
If (filelen & gt;=BUFFER_SIZE)
{

Len=sendto (mysock, buf, BUFFER_SIZE, 0, (struct sockaddr *) & amp; To_sin sendlen);

Filelen -=BUFFER_SIZE;
}
The else
{

Sendto (mysock, buf, filelen, 0, (struct sockaddr *) & amp; To_sin sendlen);
Sleep (30);
break;
}
Sleep (30);
}
fclose(fp);

Receiver:
Case MT_FILE_START:
{
//open the file
If ((fp=fopen (" C: \ \ myrecv JPG ", "wb +"))==NULL)
{
Printf (" myrecv. TXT open failure!!!!! \n");
}
}
break;
Case MT_FILE_CONTENT:
{
Fwrite (data, 1, BUFFER_SIZE, fp);
}
break;
Case MT_FILE_END:
{
Fwrite (data, 1, pHeader - & gt; NDataLength, fp);
Sleep (30);
fclose(fp);
}
break;
  • Related