Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 13:09, 15 February 2008.

CS000825 - Using an already active connection

From Forum Nokia Wiki


ID CS000825 Creation date February 15, 2008
Platform S60 3rd Edition
S60 3rd Edition, FP1
Tested on devices Nokia E90 Communicator, Nokia N95
Category Symbian C++ Subcategory Networking
APIs   Classes RHTTPSession
RSocketServ
RConnection
TCommDbConnPref
TConnectionInfoBuf
Methods      

Overview

You can use an already active RConnection to establish a connection to the Internet. This saves resources and memory.

RConnection has enumeration of the active connections. The source code finds active connections and attaches to the selected connection via the IAP. If there is no selected active connection, a new one is created. Errors are not handled in the source code.

MMP file

LIBRARY http.lib

LIBRARY ecom.lib

LIBRARY esock.lib

LIBRARY commdb.lib

CAPABILITY NetworkServices


Header file

#include <http.h>
#include <es_sock.h>
#include <commdbconnpref.h>


Source file

// Selected IAP
TInt selectedIap=6;
 
// Open socket server and connection
RHTTPSession session;     // TODO: Set to your class member variable
RSocketServ socketServ;   // TODO: Set to your class member variable
RConnection connection;   // TODO: Set to your class member variable
TCommDbConnPref connPref; // TODO: Set to your class member variable
socketServ.Connect();
connection.Open(iSocketServ);
 
// Search through existing connections.
// If there is already a connection that matches the given IAP, try to attach to
// existing connection.
TBool connected(EFalse);
TConnectionInfoBuf connInfo;
TUint count;
if ( connection.EnumerateConnections(count) == KErrNone )
    {
    for (TUint i=1; i<=count; i++)
    {
        // Note: GetConnectionInfo expects 1-based index
    if ( connection.GetConnectionInfo( i, connInfo ) == KErrNone )
        {
        if ( connInfo().iIapId == selectedIap )
        {
        if ( connection.Attach(connInfo, RConnection::EAttachTypeNormal)
        == KErrNone )
            {
            connected = ETrue;
            break;
            }
        }
        }
    }
    }
 
// Is there an active connection?
if ( !connected )
    {
    // Could not attach to the existing connection.
    // => Start a new connection.
    connPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
    connPref.SetIapId(selectedIap);
    connection.Start(connPref);
    }
 
// Open session
session.OpenL();
 
// Set the session's connection info...
RStringPool strPool = session.StringPool();
RHTTPConnectionInfo connInfo = session.ConnectionInfo();
 
// ...to use the socket server
connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketServ,
    RHTTPSession::GetTable() ), THTTPHdrVal (socketServ.Handle()) );
 
// ...to use the connection
connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketConnection,
    RHTTPSession::GetTable() ), 
    THTTPHdrVal (REINTERPRET_CAST(TInt, &(connection))) );
 
 
 
 
// TODO: Remember to close handles in your class destructor, such as:
CYourClass::~CYourClass()
    {
    session.Close(); // Close handles in this order
    connection.Close();
    socketServ.Close();
    }

See also

TSS000056 - How can I determine active connections?

Related Discussions
Thread Thread Starter Forum Replies Last Post
Active Object Crash!! isa550 General Symbian C++ 20 2006-09-14 21:03
Active Objects primal General Symbian C++ 12 2008-07-13 15:14
Mobile phones have an IP address? ovjo12 Mobile Java Networking & Messaging & Security 5 2008-01-19 12:12
Threading or active objects mayankkedia General Symbian C++ 1 2004-09-16 10:36
New call problem Bill_Murray General Symbian C++ 4 2007-05-27 15:30
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX