Namespaces
Variants
Actions
(Difference between revisions)

Using an already active connection on Symbian

Jump to: navigation, search
m
m (Hamishwillee - Adding missing translation link)
 
(9 intermediate revisions by 2 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 -->
{{KBCS}}
+
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
{{CodeSnippet
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|id=CS000825
+
|devices= Nokia E90 Communicator, Nokia N95
|platform=S60 3rd Edition<br>S60 3rd Edition, FP1
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|devices=Nokia E90 Communicator, Nokia N95
+
|platform= S60 3rd Edition<br>S60 3rd Edition, FP1
|category=Symbian C++
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|subcategory=Networking
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
|creationdate=February 15, 2008
+
|signing= Self Signed
|keywords=RHTTPSession, RSocketServ, RConnection, TCommDbConnPref, TConnectionInfoBuf
+
|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 <tt>RConnection</tt> to establish a connection to the Internet. This saves 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. 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.
+
{{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==
  
LIBRARY     http.lib
+
<code text>
 
+
LIBRARY http.lib
LIBRARY     ecom.lib
+
LIBRARY ecom.lib
 
+
LIBRARY esock.lib
LIBRARY     esock.lib
+
LIBRARY commdb.lib
 
+
CAPABILITY NetworkServices
LIBRARY     commdb.lib
+
</code>
 
+
CAPABILITY   NetworkServices
+
 
+
  
 
==Header file==
 
==Header file==
  
<code>  
+
<code cpp>  
 
#include <http.h>
 
#include <http.h>
 
#include <es_sock.h>
 
#include <es_sock.h>
Line 42: Line 52:
 
==Source file==
 
==Source file==
  
<code>
+
<code cpp>
 
// Selected IAP
 
// Selected IAP
 
TInt selectedIap=6;
 
TInt selectedIap=6;
Line 120: Line 130:
  
 
==See also==
 
==See also==
[[TSS000056 - How can I determine active connections?]]
+
[[How can I determine active connections using Symbian C++?]]
 
+
<!-- Translation --> [[zh-hans:如何使用已连接的接入点]]
[[Category:Symbian C++]][[Category:Networking]][[Category:Code Examples]][[Category:Code Snippet]]
+

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

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

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

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

This page was last modified on 13 September 2012, at 09:21.
162 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved