|
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-B8DEA3EE-7BA7-5A29-9A27-B87EE0EB254F" xml:lang="en"><title>Accessing |
|
13 TCP/IP Sockets Tutorial</title><shortdesc>This topic describes how to access TCP/IP sockets. </shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody> |
|
14 <prereq><p>You must be familiar with <codeph>RSocketServ()</codeph> and <codeph>RSocket()</codeph> to |
|
15 understand this tutorial. </p> </prereq> |
|
16 <context><p>Client programs access TCP/IP sockets through the generic socket |
|
17 interface <codeph>RSocket()</codeph>. The <codeph>RSocket()</codeph> specifies |
|
18 the protocol-specific behaviour through argument values. This tutorial contains |
|
19 notes on the usage of <codeph>RSocket()</codeph> functions for TCP and UDP |
|
20 sockets. </p><p> The high level steps to access the TCP/IP sockets are as |
|
21 follows: </p> </context> |
|
22 <steps id="GUID-613D3E19-02F2-578A-89AC-B639B8952357"> |
|
23 <step id="GUID-B608A9CE-1A99-5A6F-AE6D-63015A0BE089"><cmd>The <codeph>RSocket()</codeph> function |
|
24 takes a number of parameters that determine the type of socket connection |
|
25 to provide. </cmd> |
|
26 <info>The following are the important parameters for TCP/IP or UDP: </info> |
|
27 <substeps id="GUID-507B471D-EFD5-5DD2-B457-76AF61A863C9"> |
|
28 <substep id="GUID-1743A72D-3FB7-57CE-AF20-4CB4452334B9"><cmd/> |
|
29 <info>addrFamily </info> |
|
30 </substep> |
|
31 <substep id="GUID-111B511D-1F1B-52FD-8820-8A4F8DF7DB66"><cmd/> |
|
32 <info>sockType </info> |
|
33 </substep> |
|
34 <substep id="GUID-0049E8E2-3A84-5C5D-97ED-09367BA11259"><cmd/> |
|
35 <info>protocol </info> |
|
36 </substep> |
|
37 </substeps> |
|
38 </step> |
|
39 <step id="GUID-D63213B5-180D-5B82-A699-4CD1FF8AC066"><cmd/> |
|
40 <info>The following constant values must be used for TCP/IP: </info> |
|
41 <info>addrFamily: <codeph>KAfInet</codeph> or <codeph>KAfInet6</codeph> for |
|
42 IPv6 </info> |
|
43 <info>sockType: <codeph>KSockStream</codeph> for TCP/IP or <codeph>KSockDatagram</codeph> for |
|
44 UDP </info> |
|
45 <info>protocol: <codeph>KProtocolInetTCP</codeph> or <codeph>KProtocolInetUDP</codeph> </info> |
|
46 </step> |
|
47 </steps> |
|
48 <example><title>Example</title> <p>The following code is an example to access |
|
49 the TCP/IP socket: </p> <codeblock id="GUID-E61E7089-2F9C-5E8A-ADFB-4BF25451AA59" xml:space="preserve"> |
|
50 void Example::open(void) |
|
51 { |
|
52 TInt err; |
|
53 RSocketServ ss; |
|
54 RSocket sock; |
|
55 |
|
56 err = ss.Connect(); |
|
57 err = sock.Open(ss, KAfInet, KSockStream, KProtocolInetTcp); |
|
58 // ... now connect to the socket to send and receive data |
|
59 </codeblock> </example> |
|
60 </taskbody><related-links> |
|
61 <link href="GUID-61E0CD76-A2E3-5066-84A8-146EECA8ADCD.dita"><linktext>Sockets Server</linktext> |
|
62 </link> |
|
63 </related-links></task> |