×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    311

    how to receive a big data by socket?

    how to receive a big data by socket?

    i want receive a big data by socke, about 50K.

    in socetReader

    void CSocketsReader::RunL()
    {
    // Active object request complete handler
    switch ( iStatus.Int() )
    {
    case KErrNone:
    // Character has been read from socket
    //TBuf8<512> iBuffer;
    iEngineNotifier.ResponseReceived( iBuffer );
    if(iBuffer'data is not enough)
    {
    iSocket.RecvOneOrMore( iBuffer, 0, iStatus, iDummyLength );
    }

    break;
    case KErrDisconnected:

    break;
    default:

    break;
    }
    }


    is it can do it ?
    thanks !!

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: how to receive a big data by socket?

    In its current form it will not work (RecvOneOrMore overwrites the buffer, and SetActive is also missing). Otherwise yes, it is normal to RecvOneOrMore multiple times, and to collect the data fragments into an other buffer (you can use TBuf8 if you know the desired length in build-time, but HBufC8 or CBufFlat can be useful too), until the accumulated length meets your expectations.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    311

    Re: how to receive a big data by socket?

    Quote Originally Posted by wizard_hu_ View Post
    In its current form it will not work (RecvOneOrMore overwrites the buffer, and SetActive is also missing). Otherwise yes, it is normal to RecvOneOrMore multiple times, and to collect the data fragments into an other buffer (you can use TBuf8 if you know the desired length in build-time, but HBufC8 or CBufFlat can be useful too), until the accumulated length meets your expectations.
    thanks , what is the iDummyLength effect?
    can I appoint the amount of the data, once time receive?

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: how to receive a big data by socket?

    It is a mandatory argument of RecvOneOrMore, it gives you the amount of received data. Since iBuffer.Length also tells you that, it is rarely useful. But RecvOneOrMore needs it, and it should be a member variable.

  5. #5
    Registered User
    Join Date
    Aug 2007
    Posts
    311

    Re: how to receive a big data by socket?

    Quote Originally Posted by wizard_hu_ View Post
    It is a mandatory argument of RecvOneOrMore, it gives you the amount of received data. Since iBuffer.Length also tells you that, it is rarely useful. But RecvOneOrMore needs it, and it should be a member variable.
    HI, wizard_hu_

    my english is not enough good.

    the data like

    data head 1B
    date length 2B
    date content 5K

    in my CSocketReader

    int receiveLength = 0;
    int totallength = 0;
    TBuf<512> iBuffer;
    iBuffer.Zero(); //yh
    iSocket.RecvOneOrMore (iBuffer, 0, iStatus, iDummyLength);

    in
    void RunL()
    {
    if( totallength == 0 )
    {
    parse (iBuffer) //get totallength by the date length 2B
    receiveLength = iBuffer.Length();
    }
    else
    {
    receiveLength += iBuffer.Length();
    }

    if(receiveLength >= totallength )
    {
    receiveLength = 0;
    totallength = 0;
    }
    else
    {
    iSocket.RecvOneOrMore (iBuffer, 0, iStatus, iDummyLength);
    setActive();
    }
    }

    by the cod can i get the all data ?
    when the data is bigger than 512. i get the by the date length 2B
    is not the really data length .
    how can i do it .thanks!!!!!!!!!!!
    Last edited by lmyuanhang; 2010-05-27 at 09:44. Reason: forget the setActive();

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: how to receive a big data by socket?

    TBuf8<512>+RecvOneOrMore = receive some (one or more, up to 512) bytes, and complete as soon as possible
    TBuf8<512>+Read = receive 512 bytes

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: how to receive a big data by socket?

    What you can do is this:
    Code:
    // .h
    TBuf<512> iBuffer;
    CBufFlat *iData;
    
    // .cpp
    
    RunL()
    {
        if(iStatus==KErrNone)
        {
            iData->InsertL(iData->Size(),iBuffer);
            if(iData->Size()>=3) // header and length field is ready
            {
                TPtr8 data(iData>Ptr(0));
                TUint8 head1B=data[0];
                TUint16 length2B=256*data[2]+data[1];
                if(iData->Size()>=length2B+3)
                {
                    // you have the complete data in "data.Mid(3,length2B)"
                }
                else RecvMore();
            }
            else RecvMore();
        }
    }
    
    RecvMore()
    {
        iSocket.RecvOneOrMore(iBuffer,0,iStatus,iLen);
        SetActive();
    }

Similar Threads

  1. RSocket receive data problem.
    By hepower in forum Symbian
    Replies: 1
    Last Post: 2009-12-25, 06:49
  2. J2ME encrypt C# decrypt
    By josual in forum Mobile Java Networking & Messaging & Security
    Replies: 13
    Last Post: 2008-10-20, 04:29
  3. Emulator gets closed when data reaches on socket....
    By Amit Mahajan in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2006-05-04, 07:50
  4. GPRS connection problems on 6600..
    By suckho in forum Symbian Networking & Messaging (Closed)
    Replies: 10
    Last Post: 2005-12-02, 14:00
  5. Nokia 6600 Socket Server send delay Problem
    By dicson_hu in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2005-10-31, 07:37

Posting Permissions

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