Receive binary file through recv
From: michelle (theintangible1_at_hotmail.com)
Date: 06/25/03
- Next message: phil-news-nospam_at_ipal.net: "Re: Receive binary file through recv"
- Previous message: Sam: "Re: Size"
- Next in thread: phil-news-nospam_at_ipal.net: "Re: Receive binary file through recv"
- Reply: phil-news-nospam_at_ipal.net: "Re: Receive binary file through recv"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: 24 Jun 2003 15:19:11 -0700
Hi, I am trying to send a binary file from the client to the server.
On the client side, I have the file that I want to send to be stored
in a buffer, (array of bytes), and on the server side, I wonder when I
receive it, instead of allocate a buffer could I create a file and set
the parameter ptr in recv() to the file descriptor of the newly
created file? But either way it didn't work, and my code is
following, can someone tell me what I did wrong? Thanks!
Directly recv to file:
fid=fopen("testing", "w");
bytes=recv(clisock, fid, length, 0);
Recv to buffer then write to file:
char *buf=(char *)malloc(length*sizeof(char); (length is how many
bytes of data)
fid=fopen("testing", "w");
bytes=recv(clisock, buf, length, 0);
fwrite(buf, 1, length, fid); (the data is in unit of bytes)
fclose(fid);
- Next message: phil-news-nospam_at_ipal.net: "Re: Receive binary file through recv"
- Previous message: Sam: "Re: Size"
- Next in thread: phil-news-nospam_at_ipal.net: "Re: Receive binary file through recv"
- Reply: phil-news-nospam_at_ipal.net: "Re: Receive binary file through recv"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|