×
Namespaces

Variants
Actions
(Difference between revisions)

Using an already active connection on Symbian

From Nokia Developer Wiki
Jump to: navigation, search
tepaa (Talk | contribs)
m
hamishwillee (Talk | contribs)
m (Hamishwillee - Adding missing translation link)
 
(17 intermediate revisions by 7 users not shown)
Line 1: Line 1:
__NOTOC__
+
[[Category:Symbian C++]][[Category:Networking]][[Category:Code Snippet]][[Category:Code Snippet]][[Category:S60 3rd Edition (initial release)]][[Category:S60 3rd Edition FP1]][[Category:S60 3rd Edition FP2]]
__NOEDITSECTION__
+
{{ArticleMetaData <!-- v1.2 -->
 +
|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]]) -->
 +
|devices= Nokia E90 Communicator, Nokia N95
 +
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
 +
|platform= S60 3rd Edition<br>S60 3rd Edition, FP1
 +
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 +
|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
 +
}}
  
{|style="background:#eceff2" width="660px" border="1" cellpadding="5" cellspacing="0"
+
==Overview==
|-
+
|'''ID''' ||&nbsp;
+
|'''Creation date''' ||08.02.2008
+
|-
+
|'''Platform''' ||S60 3rd Ed. MR
+
|'''Tested on devices''' ||Nokia E90, N95
+
|-
+
|'''Category''' ||Symbian C++
+
|'''Subcategory''' ||Networking
+
|-
+
|'''APIs''' ||&nbsp;
+
|'''Classes''' ||RHTTPSession<br>RSocketServ<br>RConnection<br>TCommDbConnPref<br>TConnectionInfoBuf
+
|-
+
|'''Methods''' ||&nbsp;
+
|&nbsp; ||&nbsp;
+
|}
+
  
 +
{{Abstract|You can use an already active {{Icode|RConnection}} to establish a connection to the Internet. This saves resources and memory. }}
  
==Overview==
+
{{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.
 
+
You can use already active RConnection to get connection to internet and you save resources and memory.
+
RConnection has enumeration of the active connections. Source code below finds active connections and
+
attach to selected by IAP. If there is no selected active connection we create new one. Errors are
+
not handled in the source code.
+
  
 
==MMP file==
 
==MMP file==
  
The following libraries are required:
+
<code text>
 
+
LIBRARY http.lib
* http.lib
+
LIBRARY ecom.lib
* ecom.lib
+
LIBRARY esock.lib
* esock.lib
+
LIBRARY commdb.lib
* commdb.lib
+
CAPABILITY NetworkServices
 
+
</code>
  
 
==Header file==
 
==Header file==
  
<code>  
+
<code cpp>  
 
#include <http.h>
 
#include <http.h>
 
#include <es_sock.h>
 
#include <es_sock.h>
Line 49: Line 52:
 
==Source file==
 
==Source file==
  
<code>
+
<code cpp>
 
+
 
// Selected IAP
 
// Selected IAP
 
TInt selectedIap=6;
 
TInt selectedIap=6;
Line 63: Line 65:
  
 
// Search through existing connections.
 
// Search through existing connections.
// If there is already connection which matches to given IAP try to attach to existing connection.
+
// If there is already a connection that matches the given IAP, try to attach to
 +
// existing connection.
 
TBool connected(EFalse);
 
TBool connected(EFalse);
 
TConnectionInfoBuf connInfo;
 
TConnectionInfoBuf connInfo;
Line 70: Line 73:
 
     {
 
     {
 
     for (TUint i=1; i<=count; i++)
 
     for (TUint i=1; i<=count; i++)
{
+
    {
 
         // Note: GetConnectionInfo expects 1-based index
 
         // Note: GetConnectionInfo expects 1-based index
if ( connection.GetConnectionInfo( i, connInfo ) == KErrNone )
+
    if ( connection.GetConnectionInfo( i, connInfo ) == KErrNone )
    {
+
        {
    if ( connInfo().iIapId == selectedIap )
+
        if ( connInfo().iIapId == selectedIap )
{
+
        {
if ( connection.Attach(connInfo, RConnection::EAttachTypeNormal) == KErrNone )
+
        if ( connection.Attach(connInfo, RConnection::EAttachTypeNormal)
    {
+
        == KErrNone )
    connected = ETrue;
+
            {
    break;
+
            connected = ETrue;
    }
+
            break;
}
+
            }
    }
+
        }
}
+
        }
 +
    }
 
     }
 
     }
  
// Did we get active connection?
+
// Is there an active connection?
 
if ( !connected )
 
if ( !connected )
 
     {
 
     {
     // Could not attach to existing connection.
+
     // Could not attach to the existing connection.
 
     // => Start a new connection.
 
     // => Start a new connection.
 
     connPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
 
     connPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
Line 99: Line 103:
 
session.OpenL();
 
session.OpenL();
  
// Set the sessions connection info...
+
// Set the session's connection info...
 
RStringPool strPool = session.StringPool();
 
RStringPool strPool = session.StringPool();
 
RHTTPConnectionInfo connInfo = session.ConnectionInfo();
 
RHTTPConnectionInfo connInfo = session.ConnectionInfo();
  
// ...to use our socket server
+
// ...to use the socket server
 
connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketServ,
 
connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketServ,
 
     RHTTPSession::GetTable() ), THTTPHdrVal (socketServ.Handle()) );
 
     RHTTPSession::GetTable() ), THTTPHdrVal (socketServ.Handle()) );
  
// ...to use our connection
+
// ...to use the connection
 
connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketConnection,
 
connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketConnection,
 
     RHTTPSession::GetTable() ),  
 
     RHTTPSession::GetTable() ),  
Line 115: Line 119:
  
  
// TODO: Remember to close handles in your class destructor like:
+
// TODO: Remember to close handles in your class destructor, such as:
 
CYourClass::~CYourClass()
 
CYourClass::~CYourClass()
 
     {
 
     {
Line 126: Line 130:
  
 
==See also==
 
==See also==
http://wiki.forum.nokia.com/index.php/TSS000056_-_How_can_I_determine_active_connections%3F
+
[[How can I determine active connections using Symbian C++?]]
 
+
<!-- Translation --> [[zh-hans:如何使用已连接的接入点]]
[[Category:Symbian C++]][[Category:Networking]]
+

Latest revision as of 09:21, 13 September 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 FP2
S60 3rd Edition FP1
S60 3rd Edition (initial release)
Platform Security
Signing Required: Self Signed
Capabilities: NetworkServices
Article
Keywords: RHTTPSession, RSocketServ, RConnection, TCommDbConnPref, TConnectionInfoBuf
Created: tepaa (15 Feb 2008)
Last edited: hamishwillee (13 Sep 2012)

Contents

[edit] 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.

[edit] MMP file

LIBRARY http.lib
LIBRARY ecom.lib
LIBRARY esock.lib
LIBRARY commdb.lib
CAPABILITY NetworkServices

[edit] Header file

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


[edit] 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();
}

[edit] See also

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

This page was last modified on 13 September 2012, at 09:21.
111 page views in the last 30 days.
×