×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    17

    HTTP client - handle multiple access point

    Hi..

    I am using HTTP client to automatically update data to server from an console application.

    if phone has multiple access point, it fails to connect connect to update data. but i am able to browse internet. can any body help me?

    void CClientEngine::IssueHTTPPostL(const TDesC8& aUri,
    const TDesC8& aContentType,
    const TDesC8& aBody)
    {
    SetupConnectionL();

    // Parse string to URI
    TUriParser8 uri;
    uri.Parse(aUri);

    // Copy data to be posted into member variable; iPostData is used later in
    // methods inherited from MHTTPDataSupplier.
    delete iPostData;
    iPostData = aBody.AllocL();

    // Get request method string for HTTP POST
    RStringF method = iSession.StringPool().StringF(HTTP::EPOST,
    RHTTPSession::GetTable());

    // Open transaction with previous method and parsed uri. This class will
    // receive transaction events in MHFRunL and MHFRunError.
    iTransaction = iSession.OpenTransactionL(uri, *this, method);

    // Set headers for request; user agent, accepted content type and body's
    // content type.
    RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
    SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
    SetHeaderL(hdr, HTTP::EAccept, KAccept);
    SetHeaderL(hdr, HTTP::EContentType, aContentType);

    // Set this class as an data supplier. Inherited MHTTPDataSupplier methods
    // are called when framework needs to send body data.
    MHTTPDataSupplier* dataSupplier = this;
    iTransaction.Request().SetBody(*dataSupplier);

    // Submit the transaction. After this the framework will give transaction
    // events via MHFRunL and MHFRunError.
    iTransaction.SubmitL();

    iRunning = ETrue;
    _LIT(KConnecting,"Connecting...");
    iObserver.ClientEvent(KConnecting);
    }

    Thanks

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

    Re: HTTP client - handle multiple access point

    How does it fail exactly?
    Although the general topic of article http://www.developer.nokia.com/Commu...ice_is_offline is different, the 'else' branch at the very end of the code snippet shows how you can get the HTTP API to use a hand-picked access point.

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    17

    Re: HTTP client - handle multiple access point

    Here is the setup connection. seems, it chose fist access point only. how can i choice one by one until get connected it?


    void CClientEngine::SetupConnectionL()
    {
    _LIT(KConnecting,"Started");
    iObserver.ClientEvent(KConnecting);

    if( iConnectionSetupDone )
    return;

    iConnectionSetupDone = ETrue;

    //open socket server and start the connection
    User::LeaveIfError(iSocketServ.Connect());
    User::LeaveIfError(iConnection.Open(iSocketServ));

    // open the IAP communications database
    CCommsDatabase* commDB = CCommsDatabase::NewL(EDatabaseTypeIAP);
    CleanupStack::PushL(commDB);

    // initialize a view
    CCommsDbConnectionPrefTableView* commDBView =
    commDB->OpenConnectionPrefTableInRankOrderLC(ECommDbConnectionDirectionUnknown);

    // go to the first record
    User::LeaveIfError(commDBView->GotoFirstRecord());

    // Declare a prefTableView Object.
    CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref;

    // read the connection preferences
    commDBView->ReadConnectionPreferenceL(pref);
    TUint32 iapID = pref.iBearer.iIapId;

    // pop and destroy the IAP View
    CleanupStack::PopAndDestroy(commDBView);

    // pop and destroy the database object
    CleanupStack::PopAndDestroy(commDB);

    // Now we have the iap Id. Use it to connect for the connection.
    // Create a connection preference variable.
    TCommDbConnPref connectPref;

    // setup preferences
    connectPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
    connectPref.SetDirection(ECommDbConnectionDirectionUnknown);
    connectPref.SetBearerSet(ECommDbBearerGPRS);
    //Sets the CommDb ID of the IAP to use for this connection
    connectPref.SetIapId(iapID);

    User::LeaveIfError(iConnection.Start(connectPref));

    //set the sessions connection info
    RStringPool strPool = iSession.StringPool();
    RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();

    //to use our socket server and connection
    connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketServ,
    RHTTPSession::GetTable() ), THTTPHdrVal (iSocketServ.Handle()) );

    connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketConnection,
    RHTTPSession::GetTable() ),
    THTTPHdrVal (REINTERPRET_CAST(TInt, &(iConnection))) );
    }

  4. #4
    Registered User
    Join Date
    Jan 2011
    Posts
    17

    Re: HTTP client - handle multiple access point

    I am new to Symbian. Can any body help me? what i want is, the HTTP client automatically choose the access point. if one is not working, it should choose others one by one . for example, if no gprs, it should use WLAN. what is wrong with this code?

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,748

    Re: HTTP client - handle multiple access point

    That
    // go to the first record
    User::LeaveIfError(commDBView->GotoFirstRecord());
    part seems to pick the first access point, intentionally. CCommsDbTableView has other navigation methods of course, GotoNextRecord and GotoPreviousRecord. So the other records are also available.

  6. #6
    Registered User
    Join Date
    Jan 2011
    Posts
    17

    Re: HTTP client - handle multiple access point

    Thanks a lot for your quick reply.

    How can check whether one access point is not working and choose other access point?

    User::LeaveIfError(iConnection.Start(connectPref));

    Thanks

  7. #7
    Registered User
    Join Date
    Jan 2011
    Posts
    17

    Re: HTTP client - handle multiple access point

    hi.. wizard_hu_

    how can i capture the error that an access point is not working? could you please help me

    thanks

  8. #8
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,748

    Re: HTTP client - handle multiple access point

    Start returns a result code, it may be KErrCouldNoConnect for example. But there can be situations when the connection succeeds, but can not be used for browsing (limited use network connections, or local/ad-hoc WLAN networks for example)
    You should test what happens and when, picking a working access point from code is not trivial, and picking the 'best' one may not be possible at all.

  9. #9
    Registered User
    Join Date
    Jan 2011
    Posts
    17

    Re: HTTP client - handle multiple access point

    i modified the source code. it is not working. please help me

    void CClientEngine::SetupConnectionL()
    {
    _LIT(KConnecting,"Started");
    iObserver.ClientEvent(KConnecting);

    if( iConnectionSetupDone )
    return;

    iConnectionSetupDone = ETrue;

    User::LeaveIfError(iSocketServ.Connect());
    User::LeaveIfError(iConnection.Open(iSocketServ));
    CCommsDatabase* commDB = CCommsDatabase::NewL(EDatabaseTypeIAP);
    CleanupStack::PushL(commDB);
    CCommsDbConnectionPrefTableView* commDBView =
    commDB->OpenConnectionPrefTableInRankOrderLC(ECommDbConnectionDirectionOutgoing);
    User::LeaveIfError(commDBView->GotoFirstRecord());

    TInt errConnect;
    do
    {
    CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref;
    commDBView->ReadConnectionPreferenceL(pref);
    TUint32 iapID = pref.iBearer.iIapId;
    CleanupStack::PopAndDestroy(commDBView);
    CleanupStack::PopAndDestroy(commDB);
    TCommDbConnPref connectPref;
    connectPref.SetIapId(iapID);
    connectPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
    connectPref.SetDirection(ECommDbConnectionDirectionOutgoing);
    connectPref.SetBearerSet( ECommDbBearerGPRS | ECommDbBearerCdma2000 | ECommDbBearerLAN | ECommDbBearerCSD );
    errConnect = iConnection.Start(connectPref);

    if(errConnect!=KErrNone)
    {
    User::LeaveIfError(commDBView->GotoNextRecord());
    }

    } while (errConnect!=KErrNone);


    RStringPool strP = iSession.StringPool();
    RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();
    connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketServ,
    RHTTPSession::GetTable() ),

    THTTPHdrVal (iSocketServ.Handle()) );
    TInt connPtr = REINTERPRET_CAST(TInt, &(iConnection));
    connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketConnection,
    RHTTPSession::GetTable() ),
    THTTPHdrVal (connPtr) );
    }

  10. #10
    Registered User
    Join Date
    Jan 2011
    Posts
    17

    Re: HTTP client - handle multiple access point

    what is wrong with this code?

    void CClientEngine::SetupConnectionL()
    {
    _LIT(KConnecting,"Started");
    iObserver.ClientEvent(KConnecting);

    if( iConnectionSetupDone )
    return;

    iConnectionSetupDone = ETrue;

    User::LeaveIfError(iSocketServ.Connect());
    User::LeaveIfError(iConnection.Open(iSocketServ));
    CCommsDatabase* commDB = CCommsDatabase::NewL(EDatabaseTypeIAP);
    CleanupStack::PushL(commDB);
    CCommsDbConnectionPrefTableView* commDBView =
    commDB->OpenConnectionPrefTableInRankOrderLC(ECommDbConnectionDirectionOutgoing);

    TInt errConnect;
    Int errNext= commDBView->GotoFirstRecord();
    do
    {
    CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref;
    commDBView->ReadConnectionPreferenceL(pref);
    TUint32 iapID = pref.iBearer.iIapId;
    CleanupStack::PopAndDestroy(commDBView);
    CleanupStack::PopAndDestroy(commDB);
    TCommDbConnPref connectPref;
    connectPref.SetIapId(iapID);
    connectPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
    connectPref.SetDirection(ECommDbConnectionDirectionOutgoing);
    connectPref.SetBearerSet( ECommDbBearerGPRS | ECommDbBearerCdma2000 | ECommDbBearerLAN | ECommDbBearerCSD );
    errConnect = iConnection.Start(connectPref);

    if(errConnect!=KErrNone)
    {
    errNext=commDBView->GotoNextRecord();
    }

    } while (errConnect!=KErrNone && errNext==KErrNone);



    RStringPool strP = iSession.StringPool();
    RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();
    connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketServ,
    RHTTPSession::GetTable() ),

    THTTPHdrVal (iSocketServ.Handle()) );
    TInt connPtr = REINTERPRET_CAST(TInt, &(iConnection));
    connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketConnection,
    RHTTPSession::GetTable() ),
    THTTPHdrVal (connPtr) );
    }
    Last edited by karan1982; 2011-06-29 at 18:40.

Similar Threads

  1. HTTP Client Example- handle intenet connection and sever down error
    By kuddy_abc in forum Symbian Networking & Messaging (Closed)
    Replies: 4
    Last Post: 2010-08-07, 16:45
  2. Multiple access point selections
    By dkogias in forum Open C/C++
    Replies: 0
    Last Post: 2007-12-19, 02:00
  3. How to handle multiple HTTP transactions?
    By anand_zain76 in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2007-09-07, 15:14
  4. access point problem with http client api
    By saurabh_gyl in forum Symbian Networking & Messaging (Closed)
    Replies: 10
    Last Post: 2007-06-15, 13:19

Posting Permissions

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