×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor
    Join Date
    Sep 2005
    Posts
    57

    Problem in reading data from socket

    void CSocketsReader::RunL()
    {
    // Active object request complete handler
    //parent->ReceivedData(_L8("RUNL"));
    switch ( iStatus.Int() )
    {
    case KErrNone:
    // Character has been read from socket
    //iEngineNotifier.ResponseReceived( iBuffer );
    {
    ReceivedData(data);
    IssueRead(); // Immediately start another read
    }
    break;
    case KErrDisconnected:
    // iEngineNotifier.ReportError( MEngineNotifier::EDisconnected,
    // iStatus.Int() );
    break;
    default:
    //iEngineNotifier.ReportError( MEngineNotifier::EGeneralReadError,
    // iStatus.Int() );
    break;
    }
    }

    // -----------------------------------------------------------------------------
    // CSocketsReader::IssueRead()
    // Initiates a read from socket.
    // -----------------------------------------------------------------------------
    //
    void CSocketsReader::IssueRead()
    {
    // Initiate a new read from socket into iBuffer
    // __ASSERT_ALWAYS( !IsActive(), User::Panic( KPanicSocketsEngineRead,
    // ESocketsBadState ) );
    //iSocket.Read( iBuffer, iStatus);
    iSocket.RecvOneOrMore( iBuffer, 0, iStatus, iDummyLength );
    SetActive();
    }

    // -----------------------------------------------------------------------------
    // CSocketsReader::Start()
    // Initiates a read from socket.
    // -----------------------------------------------------------------------------
    //
    void CSocketsReader::Start()
    {
    // Initiate a new read from socket into iBuffer
    if ( !IsActive() )
    {
    IssueRead();
    }
    }

    // End of File


    in the above code my iBuffer length is 256.

    when i tries to read a data more that 256 my program is crashing.can any one tell me how to handle the read data.

    please give me some sample code for reading infinte data.

    Thanks and Regards

  2. #2
    Regular Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, Great Britain
    Posts
    98

    Re: Problem in reading data from socket

    According to the documentation for RecvOneOrMore, it should read up to 'n' bytes, where 'n' is the size of your buffer. Can you show where and how this is declared? I do very similar stuff without knowing what size of data is coming in, but I must say I declare the buffer at 1024 'just in case'. I cannot tell whether the data I receive is larger than this - I've never looked as it has never overflowed. It is possible that I never receive more than 1024 bytes, but all the documentation and sample code implies that the function will stop at the size of your descriptor.

  3. #3
    Regular Contributor
    Join Date
    Jun 2005
    Location
    Philippines
    Posts
    163

    Smile Re: Problem in reading data from socket

    Should your IssueRead() function be
    void CSocketsReader::IssueRead()
    {
    if( !IsActive() )
    {
    iSocket.RecvOneOrMore( iBuffer, 0, iStatus, iDummyLength );
    SetActive();
    }
    }
    I have almost the same code as you have but I do not encounter any problems.

  4. #4
    Super Contributor
    Join Date
    Mar 2004
    Location
    Czech Republic
    Posts
    2,037

    Re: Problem in reading data from socket

    Hi,

    I don't understand the problem, if you use 256 byte buffer and you receive 1024 bytes toy simply call RecvOneOrMore four times.. Or I didn't understand what you're asking????

    Bye
    STeN

  5. #5
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    135

    reading problem from socket

    hi,

    i am able to read data during debug time ,but when i perform write and read ,during run time ,i am unable to read data during run time

    IssueRead() {

    delete iBuffer1;

    iBuffer1 = NULL;

    iBuffer1 = HBufC8::NewL(1000);

    TPtr8 bufferPtr2(iBuffer1->Des());


    iEchoSocket->Recv(bufferPtr2,0,iStatus,iLength);

    //iEchoSocket->RecvOneOrMore(bufferPtr2,0,iStatus,iLength);


    SetActive();
    }

    i am using three active object for connect,read and write

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

    Re: reading problem from socket

    It would be safer to have "TBuf8<1000> iBuffer;" in your header. In your current code "bufferPtr2" itself is a local variable (regardless of the fact that it refers to a member variable).

Similar Threads

  1. Replies: 9
    Last Post: 2010-06-10, 12:39
  2. Socket problem
    By Smeetesh Ooka in forum Mobile Java General
    Replies: 1
    Last Post: 2004-10-07, 21:20
  3. Replies: 2
    Last Post: 2004-09-15, 22:47
  4. socket connection problem
    By bhatti81 in forum Mobile Java General
    Replies: 2
    Last Post: 2003-10-08, 14:43
  5. Problem reading a data file
    By xcoutin in forum Symbian
    Replies: 2
    Last Post: 2003-08-20, 17:54

Posting Permissions

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