Sending file problem

Login to reply to this topic.
Wed, 2005-07-20 13:45
Joined: 2004-07-15
Forum posts: 71
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 ........

Wed, 2005-07-20 14:17
Joined: 2003-04-01
Forum posts: 142
Re: Sending file problem
maybe the data has line ending or some other character that messes up the communication. To get rid of the problematic characters, you could try encoding the data using base64 for example.

yucca
Wed, 2005-07-20 16:17
Joined: 2005-06-08
Forum posts: 53
Re: Sending file problem
same question!!
Wed, 2005-07-20 19:19
Joined: 2004-07-15
Forum posts: 71
Re: Sending file problem
thanks yucca for your reply ....

but i didn't really get your idea ..... data is sent in a binary form so where the problem can be raised ....
Wed, 2005-07-20 21:58
Joined: 2005-02-18
Forum posts: 100
Re: Sending file problem
You are doing things rather complex way, so it's hard to follow and there can be many errors. However, the most obvious potential bug is your SendNextPacket

Code:
/Start Send operation
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...
Code:
iBytesSent += sendLength  ;
iStartIndex = iBytesSent - 1;
...should most likely be
Code:
iBytesSent += sendLength  ;
iStartIndex = iBytesSent;
Mon, 2005-07-25 12:41
Joined: 2004-07-15
Forum posts: 71
Re: Sending file problem
 thanks msa2 Smiley

Problem solved .... ur a life saver Smiley

if u 've any comments on code please let me know ......

  • Login to reply to this topic.