Using an already active connection on Symbian
hamishwillee
(Talk | contribs) m (Hamishwillee - Fix ArticleMetaData) |
hamishwillee
(Talk | contribs) m (Hamishwillee - Bot update - Fix metadata etc) |
||
| Line 1: | Line 1: | ||
| − | [[Category:Symbian C++]][[Category:Networking]][[Category:Code | + | [[Category:Symbian C++]][[Category:Networking]][[Category:Code Snippet]][[Category:Code Snippet]] |
| − | + | {{ArticleMetaData <!-- v1.2 --> | |
| − | + | ||
| − | + | ||
| − | {{ArticleMetaData | + | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) --> | |sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) --> | ||
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | |installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | ||
| − | |sdk=<!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) --> | + | |devices= Nokia E90 Communicator, Nokia N95 |
| − | |devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) --> | + | |sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) --> |
| − | |signing=Self Signed | + | |platform= S60 3rd Edition<br>S60 3rd Edition, FP1 |
| − | |capabilities=NetworkServices | + | |devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) --> |
| − | |author=[[User:Tepaa]] | + | |dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 --> |
| + | |signing= Self Signed | ||
| + | |capabilities= NetworkServices | ||
| + | |keywords= RHTTPSession, RSocketServ, RConnection, TCommDbConnPref, TConnectionInfoBuf | ||
| + | |language= <!-- Language category code for non-English topics - e.g. Lang-Chinese --> | ||
| + | |translated-by= <!-- [[User:XXXX]] --> | ||
| + | |translated-from-title= <!-- Title only --> | ||
| + | |translated-from-id= <!-- Id of translated revision --> | ||
| + | |review-by= <!-- After re-review: [[User:username]] --> | ||
| + | |review-timestamp= <!-- After re-review: YYYYMMDD --> | ||
| + | |update-by= <!-- After significant update: [[User:username]]--> | ||
| + | |update-timestamp= <!-- After significant update: YYYYMMDD --> | ||
| + | |creationdate= 20080215 | ||
| + | |author= [[User:Tepaa]] | ||
| + | <!-- The following are not in current metadata --> | ||
| + | |id= CS000825 | ||
}} | }} | ||
==Overview== | ==Overview== | ||
| − | You can use an already active | + | You can use an already active {{Icode|RConnection}} to establish a connection to the Internet. This saves resources and memory. |
| − | + | {{Icode|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== | ==MMP file== | ||
<code text> | <code text> | ||
| − | LIBRARY | + | LIBRARY http.lib |
| − | LIBRARY | + | LIBRARY ecom.lib |
| − | LIBRARY | + | LIBRARY esock.lib |
| − | LIBRARY | + | LIBRARY commdb.lib |
| − | CAPABILITY | + | CAPABILITY NetworkServices |
</code> | </code> | ||
Revision as of 08:26, 17 April 2012
Article Metadata
Tested with
Devices(s): Nokia E90 Communicator, Nokia N95
Compatibility
Platform(s): S60 3rd Edition
S60 3rd Edition, FP1
S60 3rd Edition, FP1
Platform Security
Signing Required: Self Signed
Capabilities: NetworkServices
Article
Keywords: RHTTPSession, RSocketServ, RConnection, TCommDbConnPref, TConnectionInfoBuf
Created: tepaa
(15 Feb 2008)
Last edited: hamishwillee
(17 Apr 2012)
Contents |
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();
}

