|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE concept |
|
11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
|
12 <concept xml:lang="en" id="GUID-E3E19113-AAEE-55C2-8016-11D492123762"><title>Creating a new sub-connection - Adding an already connected socket</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>The following example shows how an application can use a sub-connection explicitly via an <xref href="GUID-0AFDA357-EE44-3788-9CAB-162B874134BF.dita"><apiname>RSubConnection</apiname></xref> instance, and tie an already connected <xref href="GUID-D4F08503-F1EF-3531-9C3C-4AF24A6255F0.dita"><apiname>RSocket</apiname></xref> to the sub-connection that has had its properties set (parameter creation is described in separate section): </p> <codeblock id="GUID-3FCEF3CA-23AB-5040-90F9-C96A49FA4A84" xml:space="preserve">RSocketServ ss; |
|
13 RConnection conn; |
|
14 RSubConnection subconn; |
|
15 RSocket sock; |
|
16 TRequestStatus status; |
|
17 |
|
18 // Connect to ESOCK |
|
19 ss.Connect(); |
|
20 |
|
21 // Open an Connection |
|
22 conn.Open(ss, KAfInet); |
|
23 |
|
24 // Start the connection |
|
25 conn.Start(status); |
|
26 User::WaitForRequest(status); |
|
27 |
|
28 // Open a TCP socket on the connection |
|
29 sock.Open(ss, KAfInet, KSockStream, KProtocolInetTcp, conn); |
|
30 |
|
31 _LIT(KRasAddr,"10.159.24.13"); |
|
32 const TInt KEchoPort = 7; |
|
33 |
|
34 TInetAddr destAddr; |
|
35 destAddr.Input(KRasAddr); |
|
36 destAddr.SetPort(KEchoPort); |
|
37 |
|
38 // Connect the Socket to the destination over the connection (default sub-connection) |
|
39 sock.Connect(destAddr, status); |
|
40 |
|
41 // Create a new sub-connection |
|
42 subconn.Open(ss, RSubConnection::ECreateNew, conn); |
|
43 |
|
44 // Set Properties of the sub-connection |
|
45 subconn.SetParameters(…); |
|
46 |
|
47 // Move the connected socket onto the new sub-connection |
|
48 TRequestStatus status; |
|
49 subconn.Add(sock, status); |
|
50 |
|
51 // Wait for socket to added |
|
52 User::WaitForRequest(status); |
|
53 </codeblock> <p> <b>Note:</b> Error handling is not included to aid clarity. </p> </conbody></concept> |