|
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-F389671B-FC30-561B-BF48-E597D0CB2D47" xml:lang="en"><title>Using |
|
13 Secure Sockets : Tutorial</title><shortdesc>This topic describes how to use secure sockets. </shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody> |
|
14 <steps id="GUID-9C1C62FF-403D-5B8A-BB71-C6B931C23D88"> |
|
15 <step id="GUID-4C65F526-6188-5957-9F2B-EC9C697C00D7"><cmd>Open a socket using |
|
16 RSocket::Open() function and connect it with RSocket::Connect() function. </cmd> |
|
17 </step> |
|
18 <step id="GUID-3B20F63F-1CB8-5DA8-9228-5DD96EDC9C4B"><cmd/> |
|
19 <info>Create a secure socket by calling CSecureSocket::NewL() function with |
|
20 the parameters as socket and secure protocol name. </info> |
|
21 </step> |
|
22 <step id="GUID-200AFAD0-FE35-5213-9B26-CA4714F2FECC"><cmd/> |
|
23 <info>To start the application acting as a client, use the CSecureSocket::StartClientHandshake() |
|
24 function to initiate a handshake with the remote server. To start the application |
|
25 acting as a server, use the CSecureSocket::StartServerHandshake() function. </info> |
|
26 <info>The call completes with an error code, if the handshake fails. </info> |
|
27 </step> |
|
28 </steps> |
|
29 <example><title>Secure Sockets example</title> <p>In the following example |
|
30 iSocket is a reference to the already opened and connected socket and KSSLProtocol |
|
31 is the descriptor containing the name of a protocol, in this case TLS1.0. |
|
32 The function should return a pointer to the CSecureSocket. </p> <codeblock id="GUID-ADF8A6E8-87EB-5EB5-A224-0DAFC61FBD44" xml:space="preserve"> |
|
33 // Connect the socket server |
|
34 User::LeaveIfError(iSocketServ.Connect()); |
|
35 // Open the socket |
|
36 User::LeaveIfError(iSocket.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp)); |
|
37 //Connect the socket |
|
38 connectInetAddr.SetAddress(KTestAddress); |
|
39 connectInetAddr.SetPort(KSSLPort); //TLS port |
|
40 |
|
41 iSocket.Connect(connectInetAddr, iStatus); |
|
42 |
|
43 ... |
|
44 |
|
45 |
|
46 // Construct the Tls socket |
|
47 iTlsSocket = CSecureSocket::NewL(iSocket, KSSLProtocol()); |
|
48 |
|
49 // start the handshake |
|
50 iTlsSocket->StartClientHandshake(iStatus); |
|
51 |
|
52 </codeblock> </example> |
|
53 <postreq><p>Use CSecureSocket::Send() to send data over the socket. Use CSecureSocket::Recv() |
|
54 and CSecureSocket::RecvOneOrMore() to receive data from the socket. </p> </postreq> |
|
55 </taskbody></task> |