×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Regular Contributor
    Join Date
    Feb 2004
    Posts
    130

    socket sending per packet problem

    hi there...
    i have few questions

    1. what is the use of last empty line after the body of HTTP POST stands for?

    2. i send a file to server using socket HTTP POST
    if i bundled all the header n body in one big HBufC8 with an empty line after the body.. it works correct...

    but if i send through socket packet by packet in two ways
    <a> send all body file every each 512bytes without last "\r\n" being sent, i got error (apps closed), but already got some response (200 OK <-- header not full)

    <b> send all body file every each 512bytes and last "\r\n" alone, i got error (apps closed) before received any response

    <c> send all body file excpet last packet to be bundled with last "\r\n", got error too (apps closed) and not received any response.

    my codes (<c> way) looks like below:

    void CSocketsEngine::SendL()
    {
    RFs fs;
    RFile exfile;
    TInt err,len;
    HBufC8* outLine;

    User::LeaveIfError(fs.Connect());
    User::LeaveIfError(exfile.Open(fs,KEncoded,EFileRead|EFileStreamText));//read encoded text

    // use file to feed outgoing tcp conntection
    // get length file size + account & password length + constant length
    exfile.Size(len);
    len += (*iContainer.iArrayQueueGPRS)[iNumber].iUsername.Length();
    len += (*iContainer.iArrayQueueGPRS)[iNumber].iPassword.Length();
    len += (*iContainer.iArrayQueueGPRS)[iNumber].iName.Length();
    len += (*iContainer.iArrayQueueGPRS)[iNumber].iUniqueID.Length();
    len += 38;// add length of hardcoded strings (upload)

    outLine = HBufC8::NewLC(1000);

    outLine->Des().Copy(_L8("POST http://abc/xyz.php HTTP/1.1\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: "));
    outLine->Des().AppendNum(len);
    outLine->Des().Append(_L8("\r\n\r\n"));

    iSocket.Write(outLine->Des(),iTranStatus);
    User::WaitForRequest(iTranStatus);

    // output account and password so they get URL Encoded
    outLine->Des().Zero();
    outLine->Des().Append(_L8("unm="));
    outLine->Des().Append((*iContainer.iArrayQueueGPRS)[iNumber].iUsername);
    outLine->Des().Append(_L8("&pwd="));
    outLine->Des().Append((*iContainer.iArrayQueueGPRS)[iNumber].iPassword);
    outLine->Des().Append(_L8("&ttl="));
    outLine->Des().Append((*iContainer.iArrayQueueGPRS)[iNumber].iName);
    outLine->Des().Append(_L8("&sub="));
    outLine->Des().Append(_L8("MODUPLOAD"));
    outLine->Des().Append(_L8("&trx="));
    outLine->Des().Append((*iContainer.iArrayQueueGPRS)[iNumber].iUniqueID);
    outLine->Des().Append(_L8("&hex="));

    iSocket.Write(outLine->Des(),iTranStatus);
    User::WaitForRequest(iTranStatus);

    TInt pos, fileSize;
    pos = 0;
    exfile.Size(fileSize);

    //send all file except last packet
    while(iTranStatus == KErrNone && (fileSize-pos>512) )
    {
    outLine->Des().Zero();
    err = exfile.Read(outLine->Des(),512);
    pos += 512;

    if (outLine->Des().Length() == 0) break;

    iSocket.Write(outLine->Des(), iTranStatus);
    User::WaitForRequest(iTranStatus);
    }

    //bundled last packet with \r\n
    exfile.Read(outLine->Des(),512);
    outLine->Des().Append(_L8("\r\n"));
    iSocket.Write(outLine->Des(), iTranStatus);

    CleanupStack::PopAndDestroy(outLine);
    exfile.Close();
    fs.Close();

    Read();//Start CBTReadSendReader Active object to read response
    }
    Last edited by Rx-lee; 2005-04-13 at 10:33.

  2. #2
    Regular Contributor
    Join Date
    Feb 2004
    Posts
    130
    olredi solved...
    forgot the "wait for request" in the last code...
    sorry my bad

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×