|
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 task |
|
11 PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd"> |
|
12 <task id="GUID-8A5054C9-7556-5153-8CEE-FA8E5F4155AE" xml:lang="en"><title>How |
|
13 to Create an Explicitly Bound Socket</title><shortdesc>This topic describes how create an explicitly bound socket. </shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody> |
|
14 <context><p>Start the network interface connection with <xref href="GUID-BED8A733-2ED7-31AD-A911-C1F4707C67FD.dita#GUID-BED8A733-2ED7-31AD-A911-C1F4707C67FD/GUID-CB62E838-A380-309C-8B08-1F804EDB4387"><apiname>RConnection::Start()</apiname></xref> to |
|
15 create an explicitly bound socket. </p> <p><b>Creating an explicitly bound |
|
16 socket</b></p><p> Explicitly bound sockets can be created in two ways: </p> </context> |
|
17 <steps id="GUID-46A5DC4D-4DF0-400D-ACA1-D34F7DC7D2AD"> |
|
18 <step id="GUID-AF44E5D1-D088-4F16-A801-129E443B52F2"><cmd>Open a socket and bind the socket to a network interface connection.</cmd> |
|
19 <stepxmp><ul> |
|
20 <li><p> Call <xref href="GUID-D4F08503-F1EF-3531-9C3C-4AF24A6255F0.dita#GUID-D4F08503-F1EF-3531-9C3C-4AF24A6255F0/GUID-3491CE2A-A94D-34E0-B0DD-D476EE3334D7"><apiname>RSocket::Open()</apiname></xref> and pass an <xref href="GUID-BED8A733-2ED7-31AD-A911-C1F4707C67FD.dita"><apiname>RConnection</apiname></xref>. </p> <p> <xref href="GUID-BED8A733-2ED7-31AD-A911-C1F4707C67FD.dita"><apiname>RConnection</apiname></xref> binds |
|
21 to an interface corresponding to the <xref href="GUID-BED8A733-2ED7-31AD-A911-C1F4707C67FD.dita"><apiname>RConnection</apiname></xref>. </p> <p> |
|
22 In the following example code, if <codeph>iConn</codeph> corresponds to a |
|
23 WiFi <xref href="GUID-BED8A733-2ED7-31AD-A911-C1F4707C67FD.dita"><apiname>RConnection</apiname></xref> then, after a calling <xref href="GUID-D4F08503-F1EF-3531-9C3C-4AF24A6255F0.dita#GUID-D4F08503-F1EF-3531-9C3C-4AF24A6255F0/GUID-3491CE2A-A94D-34E0-B0DD-D476EE3334D7"><apiname>RSocket::Open()</apiname></xref> the |
|
24 socket is explicitly bound to WiFi. </p> <codeblock xml:space="preserve">iRecvSock.Open( ss, KAfInet, KSockStream, KProtocolInetTcp, iConn );</codeblock> </li> |
|
25 </ul></stepxmp> |
|
26 </step> |
|
27 <step id="GUID-8F737ED5-AEE8-4E3F-BBBF-F5EB4B05F815"><cmd>Open a socket and bind the socket to an IP address of the network |
|
28 interface connection.</cmd> |
|
29 <stepxmp><ul> |
|
30 <li><p> Call <xref href="GUID-D4F08503-F1EF-3531-9C3C-4AF24A6255F0.dita#GUID-D4F08503-F1EF-3531-9C3C-4AF24A6255F0/GUID-5550C9E4-2A1B-3F52-A6CF-F5822AB9DBC9"><apiname>RSocket::Bind()</apiname></xref> and bind the socket to an |
|
31 IP address of the network interface connection. </p> <p> <xref href="GUID-D4F08503-F1EF-3531-9C3C-4AF24A6255F0.dita#GUID-D4F08503-F1EF-3531-9C3C-4AF24A6255F0/GUID-5550C9E4-2A1B-3F52-A6CF-F5822AB9DBC9"><apiname>RSocket::Bind()</apiname></xref> binds |
|
32 the socket to a unique IP address of the network interface connection. </p> <p> |
|
33 The following example code shows how to open a socket and bind the socket |
|
34 to a unique IP address of the WiFi connection. </p> <codeblock xml:space="preserve">// open an implicit socket |
|
35 TInt err = iRecvSock.Open( iSs, KAfInet, KSockDatagram, KProtocolInetUdp); |
|
36 User::LeaveIfError( err ); |
|
37 // This IP address maps to WiFi in the ced.cfg file |
|
38 _LIT(KRasAddr,"192.168.220.4"); |
|
39 const TInt KPort = 7000; |
|
40 TInetAddr addr; |
|
41 err = addr.Input( KRasAddr ); |
|
42 User::LeaveIfError( err ); |
|
43 addr.SetPort( KPort ); |
|
44 // Now the socket is explicitly bound to WiFi |
|
45 err = iRecvSock.Bind( addr ); |
|
46 RDebug::Print( _L("testapp: ETH Bind() = %d"), err ); |
|
47 User::LeaveIfError( err ); |
|
48 </codeblock> </li> |
|
49 </ul><p> The following code block shows an extract from the <filepath>ced.cfg</filepath> file. |
|
50 </p><codeblock xml:space="preserve"> |
|
51 ## |
|
52 [LANService] |
|
53 ADD_SECTION |
|
54 # COMMDB_ID = 1 |
|
55 Name=Ethernet |
|
56 IfNetworks=ip |
|
57 IpNetMask=255.0.0.0 |
|
58 IpGateway=0.0.0.0 |
|
59 IpAddrFromServer=FALSE |
|
60 IpAddr=192.168.1.1 |
|
61 IpDNSAddrFromServer=FALSE |
|
62 ConfigDaemonManagerName=NetCfgExtnDhcp |
|
63 ConfigDaemonName=!DhcpServ |
|
64 FIELD_COUNT=9 |
|
65 END_ADD |
|
66 |
|
67 ADD_SECTION |
|
68 # COMMDB_ID = 2 |
|
69 Name=Ethernet WiFi |
|
70 IfNetworks=ip |
|
71 IpNetMask=255.0.0.0 |
|
72 IpGateway=0.0.0.0 |
|
73 IpAddrFromServer=FALSE |
|
74 -// This IP address maps to WiFi |
|
75 IpAddr=192.168.220.4 |
|
76 IpDNSAddrFromServer=FALSE |
|
77 IpNameServer1=194.72.6.51 |
|
78 IpNameServer2=194.72.6.52 |
|
79 ConfigDaemonManagerName=NetCfgExtnDhcp |
|
80 ConfigDaemonName=!DhcpServ |
|
81 LanServiceExtensionTableName=WLANServiceExtensionTable |
|
82 LanServiceExtensionTableRecordId=4 |
|
83 FIELD_COUNT=13 |
|
84 END_ADD |
|
85 </codeblock></stepxmp> |
|
86 </step> |
|
87 </steps> |
|
88 <result><p>The socket is explicitly bound to the specific IP address of the |
|
89 network interface connection. </p> </result> |
|
90 <example><title>Explicit binding example</title> <p>Client A creates a socket |
|
91 with explicit binding using the specified interface connection. </p> <codeblock id="GUID-8CE9B83F-0091-5230-8F80-C27793E86437" xml:space="preserve">sock1 = RSocket.Open(srv,conn);</codeblock> <p>ESock |
|
92 creates the socket within the default connection and subconnection. </p> <fig id="GUID-BE26EF30-B103-5C3B-95A8-7ED66ECFE44C"> |
|
93 <image href="GUID-B21A4858-162A-50F1-8F88-4259B7F7238E_d0e120436_href.png" placement="inline"/> |
|
94 </fig> </example> |
|
95 <postreq><p>A socket can also be opened over a sub-connection using <xref href="GUID-0AFDA357-EE44-3788-9CAB-162B874134BF.dita"><apiname>RSubConnection</apiname></xref>. |
|
96 When the socket is opened, a new Service Access Point (SAP) is created for |
|
97 the socket in <xref href="GUID-BE7D196E-357B-36BE-80BB-CCBBE00DFA90.dita"><apiname>ESock</apiname></xref>. The SAP is used to handle inbound |
|
98 and outbound data. </p> </postreq> |
|
99 </taskbody></task> |