×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor
    Join Date
    Apr 2008
    Posts
    76

    how to receive data after a delay using RSocket?

    hi guys,
    i have implemented an application that connect to a socket and read some data after giving it a message. i want to receive data if availible, if not then it should wait for it and after some time leave it after closing socket.
    my code is as below, plz tell me wats the solution , its urgent,
    thanx is advance.

    void CSocketEngine::RunL()
    {
    switch( iEngineStatus )
    {
    case EConnecting:
    if ( iStatus == KErrNone )
    {
    TBuf8<50> buffer;
    buffer.Append(iCmdMessage);
    iSocket.Write( buffer, iStatus);

    iEngineStatus = EReceived;

    iResponse.ZeroTerminate();
    TSockXfrLength reslen;
    iSocket.RecvOneOrMore(iResponse, 0, iStatus, reslen);
    User::WaitForRequest(iStatus);
    SetActive();
    }
    else
    {
    iEngineStatus = ENotConnected ;
    }
    break;
    case EReceived:
    iSocketObserver.RequestCompleted();
    CloseSocket();
    break;
    default:
    break;

    };
    }

    In this code if there is no data avalible , it goes on hang because of User::WaitForRequest(iStatus);

  2. #2
    Nokia Developer Champion
    Join Date
    Jul 2007
    Location
    ShenZhen, China
    Posts
    4,346

    Re: how to receive data after a delay using RSocket?

    Quote Originally Posted by s_mehdi76 View Post
    hi guys,
    i have implemented an application that connect to a socket and read some data after giving it a message. i want to receive data if availible, if not then it should wait for it and after some time leave it after closing socket.
    my code is as below, plz tell me wats the solution , its urgent,
    thanx is advance.

    void CSocketEngine::RunL()
    {
    switch( iEngineStatus )
    {
    case EConnecting:
    if ( iStatus == KErrNone )
    {
    TBuf8<50> buffer;
    buffer.Append(iCmdMessage);
    iSocket.Write( buffer, iStatus);

    iEngineStatus = EReceived;

    iResponse.ZeroTerminate();
    TSockXfrLength reslen;
    iSocket.RecvOneOrMore(iResponse, 0, iStatus, reslen);
    User::WaitForRequest(iStatus);
    SetActive();
    }
    else
    {
    iEngineStatus = ENotConnected ;
    }
    break;
    case EReceived:
    iSocketObserver.RequestCompleted();
    CloseSocket();
    break;
    default:
    break;

    };
    }

    In this code if there is no data avalible , it goes on hang because of User::WaitForRequest(iStatus);
    o, you code has some mistake.
    1st. when you iSocket.Write( buffer, iStatus); it's need SetActive, and server will notify you an event, the data send to server.

    and you can recv data. User::WaitRequest will block your event system until have any data or error.

    so best way is learn from C:\Symbian\8.0a\S60_2nd_FP2_SC\Series60Ex\sockets\

    it use 3 ao. one for send, one for recv, and one for user control, anytime can process any event.

    or you can change your EConnecting to three state.
    connecting: when KErrNone send Data
    Sending: When KErrNone recvon and more
    Recving: save data, if need recv again or close socket
    ----------------------------
    坚持学习, 坚持编码
    http://www.devdiv.net/
    qxiaoyuan

  3. #3
    Regular Contributor
    Join Date
    Apr 2008
    Posts
    76

    Re: how to receive data after a delay using RSocket?

    Can you share a piece of code. i don't still get your point.

    i will be thankful to you.

    Quote Originally Posted by qxiaoyuan View Post
    o, you code has some mistake.
    1st. when you iSocket.Write( buffer, iStatus); it's need SetActive, and server will notify you an event, the data send to server.

    and you can recv data. User::WaitRequest will block your event system until have any data or error.

    so best way is learn from C:\Symbian\8.0a\S60_2nd_FP2_SC\Series60Ex\sockets\

    it use 3 ao. one for send, one for recv, and one for user control, anytime can process any event.

    or you can change your EConnecting to three state.
    connecting: when KErrNone send Data
    Sending: When KErrNone recvon and more
    Recving: save data, if need recv again or close socket

  4. #4
    Nokia Developer Champion
    Join Date
    Jul 2007
    Location
    ShenZhen, China
    Posts
    4,346

    Re: how to receive data after a delay using RSocket?

    it's some demo code, be care of RSocket api param best store in CSocketEngine class, not in stack, otherwise, when func return , stack param has destroy, socketserv, acess bad param , it will panic 2 you
    Code:
    class CSocketEngine
    {
        .....
        TBuf8<50> iSendBuf;
        TSockXfrLength iRecvlen;
        TBuf8<1024> iRecvBuf;
    }
    
    
    void CSocketEngine::RunL()
    {
        switch( iEngineStatus )
        {
            case EConnecting:
            if ( iStatus == KErrNone )
            {
                iSendBuf.Copy(iCmdMessage);
                iSocket.Write( iSendBuf, iStatus);
                SetActive();
                iEngineStatus = ESending;
                break;
            }
            else
            {
                ....
            }
            
            case ESending:
            {
                iResponse.ZeroTerminate();
                iSocket.RecvOneOrMore(iResponse, 0, iStatus, iRecvlen);
                SetActive();
                iEngineStatus = ERecving;
                break;
            }
            else
            {
                ...
            }
    
            case ERecving:
            {
                if has recv all data
                {
                    iSocketObserver.RequestCompleted();
                    CloseSocket();
                }
                else
                {
                    iRecvBuf.Append(iResponse);
                    iResponse.Zero();
                    iSocket.RecvOneOrMore(iResponse, 0, iStatus, iRecvlen);
                    SetActive();
                }
            }
            default:
            break;
            
        };
    }
    ----------------------------
    坚持学习, 坚持编码
    http://www.devdiv.net/
    qxiaoyuan

  5. #5
    Regular Contributor
    Join Date
    Apr 2008
    Posts
    76

    Re: how to receive data after a delay using RSocket?

    Thanx buddy thans a lot.
    its really works
    Thankyou very muchhhhh

    Quote Originally Posted by qxiaoyuan View Post
    it's some demo code, be care of RSocket api param best store in CSocketEngine class, not in stack, otherwise, when func return , stack param has destroy, socketserv, acess bad param , it will panic 2 you
    Code:
    class CSocketEngine
    {
        .....
        TBuf8<50> iSendBuf;
        TSockXfrLength iRecvlen;
        TBuf8<1024> iRecvBuf;
    }
    
    
    void CSocketEngine::RunL()
    {
        switch( iEngineStatus )
        {
            case EConnecting:
            if ( iStatus == KErrNone )
            {
                iSendBuf.Copy(iCmdMessage);
                iSocket.Write( iSendBuf, iStatus);
                SetActive();
                iEngineStatus = ESending;
                break;
            }
            else
            {
                ....
            }
            
            case ESending:
            {
                iResponse.ZeroTerminate();
                iSocket.RecvOneOrMore(iResponse, 0, iStatus, iRecvlen);
                SetActive();
                iEngineStatus = ERecving;
                break;
            }
            else
            {
                ...
            }
    
            case ERecving:
            {
                if has recv all data
                {
                    iSocketObserver.RequestCompleted();
                    CloseSocket();
                }
                else
                {
                    iRecvBuf.Append(iResponse);
                    iResponse.Zero();
                    iSocket.RecvOneOrMore(iResponse, 0, iStatus, iRecvlen);
                    SetActive();
                }
            }
            default:
            break;
            
        };
    }

Similar Threads

  1. Replies: 3
    Last Post: 2008-09-09, 04:53
  2. GPRS connection problems on 6600..
    By suckho in forum Symbian Networking & Messaging (Closed)
    Replies: 10
    Last Post: 2005-12-02, 14:00
  3. 6600 gprs 发送大量rtp延时问题
    By dicson_hu in forum Symbian
    Replies: 9
    Last Post: 2005-11-04, 02:12
  4. 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
  5. how can I use N30 to receive data call??
    By makingmanrv in forum Nokia M2M
    Replies: 1
    Last Post: 2002-06-27, 11:01

Posting Permissions

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