Click here to Skip to main content
14,029,967 members
Rate this:
 
Please Sign up or sign in to vote.
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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
   
Comments
Member 13869869 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
Member 13869869 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?
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web06 | 2.8.190419.4 | Last Updated 4 Mar 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100