×
Namespaces

Variants
Actions
(Difference between revisions)

Using an already active connection on Symbian

From Nokia Developer Wiki
Jump to: navigation, search
Forum Nokia KB (Talk | contribs)
m (Protected "Using already active connection" [edit=sysop:move=sysop])
hamishwillee (Talk | contribs)
m (Hamishwillee - Adding missing translation link)
 
(14 intermediate revisions by 5 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]]) -->
{|style="background:#eceff2" width="660px" border="1" cellpadding="5" cellspacing="0"
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|-
+
|devices= Nokia E90 Communicator, Nokia N95
|'''ID''' ||&nbsp;
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|'''Creation date''' ||08.02.2008
+
|platform= S60 3rd Edition<br>S60 3rd Edition, FP1
|-
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|'''Platform''' ||S60 3rd Ed. MR
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
|'''Tested on devices''' ||Nokia E90, N95
+
|signing= Self Signed
|-
+
|capabilities= NetworkServices
|'''Category''' ||Symbian C++
+
|keywords= RHTTPSession, RSocketServ, RConnection, TCommDbConnPref, TConnectionInfoBuf
|'''Subcategory''' ||Networking
+
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
|-
+
|translated-by= <!-- [[User:XXXX]] -->
|'''APIs''' ||&nbsp;
+
|translated-from-title= <!-- Title only -->
|'''Classes''' ||RHTTPSession<br>RSocketServ<br>RConnection<br>TCommDbConnPref<br>TConnectionInfoBuf
+
|translated-from-id= <!-- Id of translated revision -->
|-
+
|review-by= <!-- After re-review: [[User:username]] -->
|'''Methods''' ||&nbsp;
+
|review-timestamp= <!-- After re-review: YYYYMMDD -->
|&nbsp; ||&nbsp;
+
|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 already active <tt>RConnection</tt> to get connection to internet and you save resources and memory.  
+
{{Abstract|You can use an already active {{Icode|RConnection}} to establish a connection to the Internet. This saves resources and memory. }}
<tt>RConnection</tt> 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.
+
 
 +
{{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==
  
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>
==Required Capabilities==
+
NetworkServices
+
  
 
==Header file==
 
==Header file==
  
<code>  
+
<code cpp>  
 
#include <http.h>
 
#include <http.h>
 
#include <es_sock.h>
 
#include <es_sock.h>
 
#include <commdbconnpref.h>
 
#include <commdbconnpref.h>
 
</code>  
 
</code>  
 +
  
 
==Source file==
 
==Source file==
  
<code>
+
<code cpp>
 
// Selected IAP
 
// Selected IAP
 
TInt selectedIap=6;
 
TInt selectedIap=6;
Line 60: Line 65:
  
 
// Search through existing connections.
 
// Search through existing connections.
// If there is already connection which matches to given IAP try to attach to
+
// If there is already a connection that matches the given IAP, try to attach to
 
// existing connection.
 
// existing connection.
 
TBool connected(EFalse);
 
TBool connected(EFalse);
Line 85: Line 90:
 
     }
 
     }
  
// 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 98: 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 114: 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 125: 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]][[Category:Code Examples]]
+

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.
104 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×