Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have designed server and client in MFC which does file transfer once after connection is made. For Example, I'm sending file with 200 characters from server to client but the buffer size in client's receive function is only 100(char buf[100]). if that is the case, I'm sending command to server to send remaining data. How to start sending from 101th character?

What I have tried:

Server :
CFile Sourcefile;
Sourcefile.Open(strFilePath, CFile::modeRead);
ULONGLONG dwLength = Sourcefile.GetLength();
command_header.Databuffer = new char[(int)dwLength + 1];
UINT nActual = Sourcefile.Read(command_header.Databuffer,dwLength);
command_header.Databuffer[nActual] = 0;
nRet = SockConnection.Send(command_header.Databuffer, nActual);


Client :
nRet = SockConnection.Receive(iBuf, 100);
while(iBuf[nRet] != '\0') {
AfxMessageBox(L"Send remaining data");
hCommand_header.command = FILE_SIZE;
nRet = SockConnection.Send((char*)&hCommand_header.command, sizeof(hCommand_header.command));
Posted
Updated 4-Mar-19 9:57am

1 solution

The server is sending all the data in a single transmission, so there is no more work for it to do. The client needs to build the file by writing each block to disk as it receives it. The only problem for you is that the client has no way of knowing when all the data has been received. You need to create a message protocol between the two systems so they can pass information about the amount of data that is being transmitted.
 
Share this answer
 
Comments
rmdsagar 5-Mar-19 2:31am    
Thanks! Would you prefer checksum? if so, I'm trying to use ShellExecute() to calculate checksum of file transferred.
ShellExecute(NULL, L"runas", L"cmd.exe",
L"cksum ‪C:\\cplic.log",
NULL, SW_SHOWNORMAL);


apparently it didn't work. Please throw some light how to calculate checksum simply. Thank you
Richard MacCutchan 5-Mar-19 3:47am    
For a start don't use ShellExecute, add some code inside your program. A checksum is only any use after all the data has been transferred, to check that nothing got lost or corrupted. But it does not help you to find out how many messages have been lost. Start by sending some information about the file and how much data will be transferred. You can then add a prefix to each block which indicates how many bytes it contains, and whether it is the last block in the set. Never assume that whatever you receive is everything that was sent.
rmdsagar 5-Mar-19 2:53am    
Ok! somehow ended up like this:
HINSTANCE Checksum = ShellExecute(NULL, L"runas", L"cmd.exe",
L"/k cksum C:\\cplic.log",
NULL, SW_SHOWNORMAL);
Now I get the checksum value of log file as "3009825132".
Is this right?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900