This tutorial describes how to start an RConnection connection. Each connection must be started to link the connection with the network interface hardware.
Implicit Connection Startup
In the following example, the application is unaware of the connection and does not have an instance of RConnection . This might be used if an application tries to connect a socket or resolve a name and the socket server detects that a connection has not been started. This example does not differ from previous versions of the Symbian platform.
Note: Error handling is not included to aid clarity.
RSocketServ ss; RSocket sock; TRequestStatus status; // Connect to the socket server ss.Connect(); // Open a TCP socket sock.Open(ss, KAfInet, KSockStream, KProtocolInetTcp); _LIT(KRasAddr,"10.159.24.13"); const TInt KEchoPort = 7; TInetAddr destAddr; destAddr.Input(KRasAddr); destAddr.SetPort(KEchoPort); // Request the Socket to connect to the destination (implicit Connection) sock.Connect(destAddr, status);
The following example shows how an application can start a connection explicitly via an RConnection instance, and tie an RHostResolver and RSocket to the connection started.
The application is able to override the connection preference settings in CommDb allowing it to specify the Network, IAP, ISP and bearer used. Code examples are given for the cases with and without overrides.
See TCommDbConnPref for information about how to set up the connection.
RSocketServ ss; TRequestStatus status; RConnection conn; _LIT(KRasAddr,"10.159.24.13"); const TInt KEchoPort = 7; TInetAddr destAddr; destAddr.Input(KRasAddr); destAddr.SetPort(KEchoPort); // Connect to the socket server ss.Connect(); // Open an RConnection object. Note that you must provide the RSocketServ object conn.Open(ss); // Create overrides TCommDbConnPref prefs; prefs. SetDialogPreference(ECommDbDialogPrefDoNotPrompt); prefs.SetDirection(ECommDbConnectionDirectionOutgoing); prefs.SetIapId(4); // Start an Outgoing Connection with overrides conn.Start(prefs); // Open a Host Resolver associated with the connection RHostResolver hr; hr.Open(ss, KAfInet, KProtocolInetTcp, conn); // Open a Socket associated with the connection RSocket sock; sock.Open(ss, KAfInet, KSockStream, KProtocolInetTcp, conn); // Request the Socket to connect to the destination sock.Connect(destAddr, status);
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.