Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Using an already active connection on Symbian

From Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia E90 Communicator, Nokia N95
Platform(s): S60 3rd Edition
S60 3rd Edition, FP1
S60 3rd Edition FP2
S60 3rd Edition FP1
S60 3rd Edition (initial release)
Platform Security
Signing Required: Self Signed
Capabilities: NetworkServices
Keywords: RHTTPSession, RSocketServ, RConnection, TCommDbConnPref, TConnectionInfoBuf
Created: tepaa (15 Feb 2008)
Last edited: hamishwillee (13 Sep 2012)



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
// 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;
// Is there an active connection?
if ( !connected )
// Could not attach to the existing connection.
// => Start a new connection.
// Open session
// Set the session's connection info...
RStringPool strPool = session.StringPool();
RHTTPConnectionInfo connInfo = session.ConnectionInfo();
// use the socket server
connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketServ,
RHTTPSession::GetTable() ), THTTPHdrVal (socketServ.Handle()) );
// 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:
session.Close(); // Close handles in this order

See also

How can I determine active connections using Symbian C++?

This page was last modified on 13 September 2012, at 06:21.
49 page views in the last 30 days.