|
-
January 18th, 2003, 10:12 AM
#1
Remotely copying a file
I've got a portion of code in a program that if selected, the server sends a client a copy of a specified file. It works, but whenever the sever is finished sending the client all the data in the file, the server stops sending, but the client continuously loops waiting for the end of the file. I'm having trouble determining eof for the client. The code I have is:
Server Code:
if(stricmp(msg, "COPY")==0)
{
FILE *fileIn;
char list[61];
char file[200];
int numread;
recv(client, file, sizeof(file), 0);
if((fileIn = fopen(file, "r+b")) != NULL )
{
/* Attempt to read in 60 characters */
while(!feof(fileIn))
{
numread = fread(list, sizeof(char), 60, fileIn);
send(client, list, sizeof(list), 0);
}
fclose(fileIn);
}
else
{
strcpy(msg, "problem opening the file");
send(client, msg, sizeof(msg), 0);
}
}
else
And the Client Code:
if(stricmp(command, "COPY")==0)
{
FILE *outFile;
char file[500];
char list[61];
int numread = 0;
send(client, command, sizeof(command), 0);
cout << "File -> ";
cin.getline(file, 500, '\n');
send(client, file, sizeof(file), 0);
numread = recv(client, list, sizeof(list), 0);
if(stricmp(list, "PROBLEM OPENING THE FILE")==0)
{
cout << list << endl;
}
else
{
outFile = fopen("C:\\SpikesCopy.txt", "w+b");
while(list[numread] != NULL)
{
fwrite(list, sizeof(char), numread, outFile);
numread = recv(client, list, sizeof(list), 0);
}
fwrite(list, sizeof(char), numread, outFile);
fclose(outFile);
cout << "Stopped receiving." << endl;
}
}
else
For now, the client loops to recv until it hit's NULL. I thought NULL was the end of file, but this code does not work. Any help would be greatly appreciated. I've been stuck on this problem for a while.
Last edited by orbitalne; January 18th, 2003 at 12:19 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|