Link to home
Start Free TrialLog in
Avatar of Students
Students

asked on

File Sending Problem

I using Pocket PC 2002(Client) Destop Windows 2000 (Server). I am trying to send a file(sound file) from the server to the client through WIRELESS. Aftering sending, my file on the Pocket PC cannot be used. But..

When i try it on a Desktop to Desktop(also wireless), the file can be use.

I also tried sending a workable file from the Pocket PC 2002 to Desktop. It is also workable. So no problem with my codes i think.

I'm using CSocket and C++ for my coding.

Any Help or Advice is appreciated.
THnaks
Avatar of Students
Students

ASKER

What i found out is that: i think i miss reading the first byte.

I tested out by sending a txt file to the PDA and retrieve it again through active sync. the first letter of the txt file is missing.

Can someone check my algorith.

int nBytesRead = sockClient.Receive(&dataLength, 4); // Getting the data length send from the server//
               
          byte* receivedData = new byte[dataLength];

          nBytesRead = 0;

          long dataLengthTemp = dataLength;

          MessageBox(_T("Checking data integrity!!!"));

          while (dataLength != nBytesRead) {
               int dataReadLen = sockClient.Receive(receivedData + nBytesRead, dataLength - nBytesRead);
               nBytesRead += dataReadLen;
          };
     
          sockClient.Receive(receivedData, dataLength);

          CFile destFile(readFile, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary);
         
          destFile.Write(receivedData, dataLength);

Sorry for the trouble.. I have solve this problem thanx
Avatar of DanRollins
You are not checking for a potential error in the Recieve call.  It can return SOCKET_ERROR, which I believe equates to -1

That loops looks a little funny.  I'd just use:

byte* p= receivedData;
int nBytesLeft= dataLength;
while( nBytesLeft > 0 ) {
        int nActual= sockClient.Receive(p,nBytesLeft);
        if (nActual == SOCKET_ERROR || nActual == 0) {
             // handke the error
        }
        nBytesLeft -= nActual;
};
(note: I did not verify the above code).  

If that is not the problem, then show the code that is sending the data.

-- Dan
u can ask for refund of points on community support
What was the problem?
-- Dan
Dear expert(s),

A request has been made to close this Q in CS:
https://www.experts-exchange.com/questions/20546050/Refuned.html

Without a response in 72 hrs, a moderator will finalize this question by:

 - Saving this Q as a PAQ and refunding the points to the questionner

When you agree or disagree, please add a comment here.

Thank you.

modulo

Community Support Moderator
Experts Exchange
There would be much more value in the PAQ if Students would take a few moments to describe what he did to solve the problem.  Lacking that, I'd recommend a simple delete.

Students, can you describe what you did to solve this problem?  Thanks!

-- Dan
When i send a txt file over .. the first text was missing, so i thought that i started reading at the wrong time.

sockClient.Receive(receivedData, dataLength);

when i replaced the above statemtent with

sockClient.Receive(receivedData+datalength+1, dataLength);

the space will moved to the length of the file + 1

         

ASKER CERTIFIED SOLUTION
Avatar of Mindphaser
Mindphaser

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial