Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User emillaud's Avatar
    Join Date
    May 2006
    Posts
    30
    Hi
    My function RUNL is never called with the following code. I anyone has an idea, i don't undertasnd why ?
    Regards
    ERIC




    #include "HttpEventHandler.h"


    CHttpEventHandler::~CHttpEventHandler()
    {
    Cancel();
    }

    CHttpEventHandler* CHttpEventHandler::NewL(CXcv1Engine& pengine)
    {
    CHttpEventHandler* me = new (ELeave) CHttpEventHandler(pengine);
    CActiveScheduler::Add(me);
    //me->ConstructL();
    return me;
    }

    void CHttpEventHandler::SetEngine(CXcv1Engine* pengine)
    {
    //engine=pengine;

    }

    CHttpEventHandler::CHttpEventHandler(CXcv1Engine& pengine):
    CActive(CActive::EPriorityStandard),engine(pengine)
    {
    }

    void CHttpEventHandler:oCancel()
    {
    iSocket.CancelAll();
    }

    void CHttpEventHandler::GetData(const TDesC& aServ,const TDesC& aDoc)
    {
    if (IsActive()) return;
    TInt res=iSocketSrv.Connect();
    if (res!=KErrNone)
    {
    Cleanup(res);
    return;
    }
    res=iSocket.Open(iSocketSrv,KAfInet,KSockStream,KProtocolInetTcp);
    if (res!=KErrNone)
    {
    Cleanup(res);
    return;
    }
    /* res=iResolver.Open(iSocketSrv,KAfInet,KProtocolInetTcp);
    if (res!=KErrNone)
    {
    Cleanup(res);
    return;
    }*/
    ipAddr.Copy(aServ);
    iUrlDoc.Copy(aDoc);
    iState=EConnecting;
    TInetAddr destAddr;
    //destAddr.Copy(ipAddr);
    destAddr.SetAddress(INET_ADDR(10,22,98,56));
    destAddr.SetPort(8090);
    iState=EConnecting;
    iSocket.Connect(destAddr,iStatus);
    SetActive();
    }


    void CHttpEventHandler::RunL()
    {
    TBuf<50> msg;
    xcU32 j;
    if (iStatus!=KErrNone)
    {
    Cleanup(iStatus.Int());
    }
    else
    {
    switch (iState)
    {
    case EResolvingName:
    {
    TInetAddr destAddr;
    //destAddr=iNameEntry().iAddr;
    destAddr.Copy(ipAddr);
    destAddr.SetPort(8080);
    iState=EConnecting;
    iSocket.Connect(destAddr,iStatus);
    SetActive();
    break;
    }
    case EConnecting:
    {
    _LIT(KCRLF,"\xD,\xA");
    _LIT(KGetCommand,"Get ");
    TBuf8<300> getBuff;
    getBuff.Copy(KGetCommand);
    getBuff.Append(iUrlDoc);
    getBuff.Append(KCRLF);
    iState=ESending;
    iSocket.Send(getBuff,0,iStatus);
    SetActive();
    break;
    }
    case ESending:
    {
    iState=EReceiving;
    iSocket.RecvOneOrMore(iWebBuff,0,iStatus,iLen);
    SetActive();
    break;
    }
    case EReceiving:
    {
    if (iStatus!=KErrEof)
    {
    if (engine.GetWaitnb()==1)
    {
    engine.nb=iWebBuff[0]+iWebBuff[1]*256+iWebBuff[2]*65536+iWebBuff[3]*16777216;
    }
    else if (engine.GetWaitfile()==1)
    {

    }
    else
    {
    /*TPtr8 ptr = buf->Des();
    char * pchr = (char *)ptr.Ptr();
    int t=dataChunk.Length();*/
    // engine->dec.FillBuffer((unsigned char*)iWebBuff,iLen);
    }
    SetActive();
    }
    else
    {
    iSocket.Close();
    iResolver.Close();
    iSocketSrv.Close();
    }
    break;
    }
    default:
    ASSERT(EFalse);
    }
    }
    }

    void CHttpEventHandler::HandleError(TDesC& aErrMsg)
    {
    iSocket.Close();
    iResolver.Close();
    iSocketSrv.Close();
    }




    void CHttpEventHandler::ConstructL()
    {
    }

    void CHttpEventHandler::Cleanup(TInt aError)
    {
    iSocket.Close();
    iSocketSrv.Close();
    iResolver.Close();
    TBuf<50> errStr;
    if (aError!=KErrNone)
    {
    switch(iState)
    {
    case EResolvingName:
    {
    _LIT(KErrStr,"Error resolving name");
    errStr.Copy(KErrStr);
    break;
    }
    case EConnecting:
    {
    _LIT(KErrStr,"Error connecting to server");
    errStr.Copy(KErrStr);
    break;
    }
    case ESending:
    {
    _LIT(KErrStr,"Error sending request");
    errStr.Copy(KErrStr);
    break;
    }
    case EReceiving:
    {
    _LIT(KErrStr,"Error receiving data");
    errStr.Copy(KErrStr);
    break;
    }
    default:
    {
    _LIT(KErrStr,"Error unknow");
    errStr.Copy(KErrStr);
    break;
    }
    }
    //engine->
    }
    }

  2. #2
    Nokia Developer Moderator wizard_hu_'s Avatar
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    27,744
    What is in your .h file, and how do you use this class?
    Note that everything involved in asynchronous requests should be a member variable, thus having an iDestAddr would be better..

  3. #3
    Registered User emillaud's Avatar
    Join Date
    May 2006
    Posts
    30
    this is my .h file

    i call from another class Engine with engine.GetData() function



    // HttpEventHandler.h


    #include <e32base.h>
    #include <http\mhttptransactioncallback.h>
    #include "xcv1Engine.h"
    #include <ES_SOCK.H>
    #include <in_sock.h>

    class CHttpEventHandler : public CActive

    {
    public:
    ~CHttpEventHandler();
    static CHttpEventHandler* NewL(CXcv1Engine& pengine);
    void SetEngine(CXcv1Engine* pengine);
    void GetData(const TDesC& aServ,const TDesC& aDoc);
    enum TLoadState
    {
    EResolvingName,
    EConnecting,
    ESending,
    EReceiving
    };
    protected:
    void RunL();
    void DoCancel();
    CHttpEventHandler(CXcv1Engine& pengine);
    void ConstructL();
    void HandleError(TDesC& aErrMsg);
    private:
    TLoadState iState;
    TBuf8<100> iUrlDoc;
    RSocketServ iSocketSrv;
    RSocket iSocket;
    TNameEntry iNameEntry;
    RHostResolver iResolver;
    TBuf8<20000> iWebBuff;
    TSockXfrLength iLen;
    void Cleanup(TInt aError);
    TBuf8<100> ipAddr;

    CXcv1Engine& engine;
    };

  4. #4
    Nokia Developer Moderator wizard_hu_'s Avatar
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    27,744
    In fact your connection code seems to be fine, besides the local TInetAddr variable. Check if your network works (due to the 10.x.y.z address I guess you are using the emulator).
    Also note that - even it is commented now:
    //destAddr.Copy(ipAddr);
    should be
    Code:
    //iDestAddr.Input(ipAddr);
    at least if you want it to work.

  5. #5
    Registered User emillaud's Avatar
    Join Date
    May 2006
    Posts
    30
    yes networks works fine because when i used the HTTP API it works.
    But i don't understand why it is not working with socket

  6. #6
    Registered User emillaud's Avatar
    Join Date
    May 2006
    Posts
    30
    For information , i am in UIQ GUI application not in Console application

  7. #7
    Registered User emillaud's Avatar
    Join Date
    May 2006
    Posts
    30
    now RUNL is called but i have iStatus=-2 after connect function.

Similar Threads

  1. Problems with active objects, RunL() not called
    By Ewent in forum Symbian C++
    Replies: 6
    Last Post: 2007-06-15, 09:16
  2. RunL function is not called right away after SetActive()
    By huangkuan in forum Symbian Networking & Messaging (Closed)
    Replies: 8
    Last Post: 2007-05-09, 04:14
  3. ActiveObject RunL is called just once
    By lskmao in forum Symbian C++
    Replies: 3
    Last Post: 2007-01-18, 15:15
  4. Replies: 5
    Last Post: 2006-03-10, 07:37
  5. RunL() is called when creating CAknWaitDialog
    By Thomas_ in forum Symbian C++
    Replies: 2
    Last Post: 2004-11-11, 09:59

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved