Sending file problem
| Wed, 2005-07-20 13:45 | |
|
hii all
i' m sending files from mobile to computer over gprs connection using TCP/ IP protocol , butit sends rubbish instead of the real data don't know why but i t worked well on data less than 1 Kb Here it's code snippet for my AO for sending the RunL method : Code: void CSocketWriter::RunL() { if(iStatus == KErrNone ) { switch(iSocketStatus) { case ESending: SendNextPacket(); break; case EDataSent : iWaitDialog->ProcessFinishedL(); iSocket.CancelWrite(); break; } } } the Method used to load the file and create the header Code: void CSocketWriter::LoadFile(TDesC16& aFilePath) { RFs fileSession ; RFile file; TInt size; TParse filePath; //fill TParse to get filename.ext automatically filePath.Set(aFilePath,NULL,NULL); //connect to file Server fileSession.Connect(); //Read required data in binary format file.Open(fileSession,aFilePath,EFileRead); file.Size(size); iDataToSend = HBufC8::NewL(270 + size); TPtr8 ptr(iDataToSend->Des()); TBuf8<270> header; //Create Header header.AppendNum(0); header.AppendNumFixedWidth(size,EDecimal,10); header.AppendNumFixedWidth(filePath.NameAndExt().Length(),EDecimal,3); header.Append(filePath.NameAndExt()); //Read binary data to buffer HBufC8 * buf = HBufC8::NewLC(size); file.Read(buf->Des()); //Trim Spaces from right to minimize length header.TrimRight(); //Insert Header ptr.Insert(0,header); //Close file file.Close(); //Close Session fileSession.Close(); CleanupStack::Pop(buf); IssueSendL(); } the IssueSend To start sending the file Code: void CSocketWriter::IssueSendL() { //write data to buffer iWaitDialog = new (ELeave) CAknWaitDialog((REINTERPRET_CAST(CEikDialog**,&iWaitDialog)),ETrue); iWaitDialog->SetTextL(_L("Sending....")); iWaitDialog->ExecuteLD(R_WAITDIALOG); //No Request Outstanding if( !IsActive() ) { iBytesSent = 0; iStartIndex = 0; SendNextPacket(); } }//Write SendNExtPacket which is used to send the packets : Code: void CSocketWriter::SendNextPacket() { TInt sendLength; //number of bytes to be sent TInt bytesLeft = iDataToSend->Length() - iBytesSent; //bytes left (not sent yet ) if( bytesLeft < 1024) { sendLength = bytesLeft ; } else sendLength = 1024 ; //Start Send operation TPtrC8 arr =iDataToSend->Mid( iStartIndex , sendLength ) ; iSocket.Send(arr,KSIWriteOnly,iStatus,iLength); iBytesSent += sendLength ; iStartIndex = iBytesSent - 1; if(iBytesSent == iDataToSend->Length() ) {iSocketStatus = EDataSent ; } else iSocketStatus = ESending ; SetActive(); } any idea where is the problem thanks in advance ........ |
|






Forum posts: 142
yucca
Forum posts: 53
Forum posts: 71
but i didn't really get your idea ..... data is sent in a binary form so where the problem can be raised ....
Forum posts: 100
TPtrC8 arr =iDataToSend->Mid( iStartIndex , sendLength ) ;
iSocket.Send(arr,KSIWriteOnly,iStatus,iLength);
Your "arr" can be destroyed (be out of scope), before the socket server has accessed it. You need to move it into member variable. Also, I have no clue what KSIWriteOnly is supposed to do with TCP.
This is common error. People don't realize that the 'arr' is passed as a pointer to the descriptor which in local stack (in C syntax, the equivalent would be. Send(&arr, KSIWriteOnly, &iStatus, &iLength)).
Oh, and...
iStartIndex = iBytesSent - 1;
iStartIndex = iBytesSent;
Forum posts: 71
Problem solved .... ur a life saver
if u 've any comments on code please let me know ......