×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Oct 2003
    Location
    Jakarta, Indonesia
    Posts
    53

    Receive uncomplete HTTP response

    Hi Symbianish,

    I have created an application that can connect to server using HTTP connection and send HTTP request to the server, then read the HTTP response.
    It works well on the response that contain text message (the length of the message on average not exceed 1000 bytes). Now I want to connect to server and get picture or midi to my application using HTTP connection. So The HHTP response should contain binary bytes of the picture/midi file. The problem is I received uncomplete bytes of it.
    I used RSocket's RecvOneOrMore() funtion to read the response. I also defined a receive Buffer with length more than the picture/midi's length. Why I received uncomplete bytes? If I used RecvOneOrMore again after the first one reveive, Does the function will receive the rest of the bytes? I know that HTTP is connectionless, means one request get one response.
    Does anyone has done this before?

    Lots of thanks

  2. #2
    Regular Contributor
    Join Date
    Feb 2004
    Posts
    51
    You have to read until you get KErrEof

  3. #3
    Regular Contributor
    Join Date
    Oct 2003
    Location
    Jakarta, Indonesia
    Posts
    53
    hai Josef, thx for your reply...
    I would try that.
    Before yours, I solve the case with try to know how much is the length of the package will be (I Get it by issuing request to the server before the download action, just to know how much the content length that i want to download). So My engine will try to read again if the content length hasnt exceed the final length... But I think your suggestion is more flexible...Thanks man...

  4. #4
    Super Contributor
    Join Date
    Apr 2003
    Location
    Czech Republic
    Posts
    915
    Just a short note. End of file is in this case undistinguishable from closing down the connection for some other (meaning error) reason. You always get -25 error... Then it is up to you to decide if you received it because of the file was sent and no more data are available or if some illegal conditions occured...

  5. #5
    Regular Contributor
    Join Date
    Oct 2003
    Location
    Jakarta, Indonesia
    Posts
    53
    Hi
    Thx evryone..
    I tried that, and got no luck. The KErrEof never gets called. And I think the engine is still trying to read. I know there isnt any data left to read, so it should give status KErrEof on run function.
    This is sniipet of my code from CSocketReader:

    void CSocketReader::IssueRead()
    {
    __ASSERT_ALWAYS(!IsActive(), User::Panic(KPanicSocketEngineRead, ESocketBadState));
    iSocket.RecvOneOrMore(iBuffer, 0, iStatus, iDummyLength);
    SetActive();
    }
    void CSocketReader::RunL()
    {
    switch (iStatus.Int())
    {
    case KErrNone:
    WriteToBufferL(iBuffer);
    IssueRead();
    break;
    case KErrEof:
    iEngine.ResponseReceived(iCompleteBuffer->Des());
    break;
    case KErrDisconnected:
    iEngine.ReportError(CSocketEngine::EDisconnected);
    break;
    default:
    iEngine.ReportError(CSocketEngine::EGeneralReadError);
    break;
    };
    }
    //the next code here, I've got it from someone's post in the forum, thanks for that..(But I havent test it yet, due to this KErrEof problem)
    void CSocketReader::WriteToBufferL(const TDesC8& abuf)
    {
    if(iCompleteBuffer->Des().Length() + abuf.Length() < iCompleteBuffer->Des().MaxLength())
    {
    iCompleteBuffer->Des().Append(abuf);
    }
    else
    {
    // dynamically reallocate more space if necessary
    iCompleteBuffer = iCompleteBuffer->ReAllocL(iCompleteBuffer->Length()+abuf.Length());
    iCompleteBuffer->Des().Append(abuf);
    }
    }

    Why this code isn't lettin me to get the KerrEof?
    Lots of thanks

  6. #6
    Registered User
    Join Date
    Nov 2003
    Posts
    6

    Use the "Content-Length" field to know when to stop

    I had the same problem and what I did was to keap reading one chunk at a time untill I get the KErrEof OR untill I got all the bytes that the "Content-Length" field in the HTTP header specified - at which point I would cancel the remaining READ operation.

    Ken

  7. #7
    Regular Contributor
    Join Date
    Oct 2003
    Location
    Spain
    Posts
    329

    I'm getting the same problem when receiving Bluetooth info.

    Hi there,

    I'm also facing the same problem.

    In my case the sender always close the connection after the whole message has been sent.
    But in the receiver side it's missing information.

    I don't know why this is happening. I've tried several buffer size, several methods (such as Recv(), Read() or the mentioned above)...

    apitoman:
    maybe this help you: when disconnected you should write the buffer to the complete buffer
    Code:
    case KErrDisconnected:
         WriteToBufferL(iBuffer);
         iEngine.ReportError(CSocketEngine::EDisconnected);
    break;
    But still it's not enough for me.

    Thanks

Posting Permissions

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