Posted by Loser[TM] on 04:57:00 08-14-2003
I have a problem.
I wrote this:
Code:
//Sending:
/*
server is receiving files.
At first, the program sends the filename to server to create a file for writing.
then it sends a length of a file, which is stored in
static long llength;
This part of code fills a buffer and send it*/
#define BS 256
static char buffer[BS];
static short eof=0;
static long status = 0;
while(eof == 0){
for(short temp = 0; temp < BS; temp++){
status++;
if(status <= llength){
buffer[temp] = (char)getc(input);
}
else{
status = 0;
eof = 1;
break;
}
}
send(server, buffer, strlen(buffer), 0);
}
//on the other side, receiving:
static char buffer[BS];
static short eof = 0;
static long status = 0;
while(eof == 0){
recv(client, buffer, BS, 0);
for(short temp = 0; temp < BS; temp++){
status++;
if(status <= llength){
putc((int)buffer[temp], output);
}
else{
eof = 1;
break;
}
}
}
This works fine with text files, but when I want to send *.mp3 or exe file, it stops.
So I'm asking you to tell e what is wrong.
And if there is any other way to send an exe file, please, tell me.
_________________
Loser™
[ This Message was edited by: Loser[TM] on 2003-08-14 04:58 ]
Posted by dxprog on 08:24:00 08-14-2003
You're trying to send binary files in text format. I'm not sure how one would correct the problem, but I think that's what the problem is.
[addsig]
Posted by Smerdyakov on 08:48:00 08-14-2003
strlen() determines the length of its parameter by searching for the first 0 character in it. This makes your method fail for files that contain 0's in them, which any file containing something besides human-readable text is likely to contain. This shouldn't be a problem for you, though, because you are already tracking the length of the buffer with a variable. You should be checking the send() return value to see if all of your buffer is really sent in one call, however.
[ This Message was edited by: dxprog on 2003-08-14 09:09 ]
Posted by Neu[Mann] on 11:37:00 08-14-2003
dxprog, I'm very sad to see you banned Smerdyakov because he ANSWERED A QUESTION...
Posted by dxprog on 11:54:00 08-14-2003
That's why I didn't delete his post alltogether. He answered it, but his constant "You shouldn't be using this language" thing NEEDS TO STOP!!!!!
_________________
When I got VB, i could have flown without thrusters and shot down TIE Interceptors just by spitting at them.
[ This Message was edited by: dxprog on 2003-08-14 11:54 ]
Posted by KaGez on 11:58:00 08-14-2003
And I do stand behind dxprog's decision. if you think he did it wrong, try to convince me first.
He did the right thing.
Btw, smerdy is unbanned again (for now)
[addsig]
Posted by Smerdyakov on 12:16:00 08-14-2003
I didn't say he shouldn't be using C. I asked him why he was using it. There is a significant difference. I think it would be appropriate for you to apologize.
Posted by Loser[TM] on 14:33:00 08-14-2003
Quote:
On 2003-08-14 08:48, Smerdyakov wrote:
strlen() determines the length of its parameter by searching for the first 0 character in it. This makes your method fail for files that contain 0's in them, which any file containing something besides human-readable text is likely to contain. This shouldn't be a problem for you, though, because you are already tracking the length of the buffer with a variable. You should be checking the send() return value to see if all of your buffer is really sent in one call, however.
Yes,yes, that was the problem. I knew it will be so simple answer. Now it woks. Thanks a lot. : )
_________________
Loser™
[ This Message was edited by: Loser[TM] on 2003-08-14 14:35 ]