Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

CSecureSocket example

From Wiki
Jump to: navigation, search
Article Metadata
Code ExampleArticle
Created: Carbider (29 Nov 2007)
Last edited: hamishwillee (30 May 2013)


Introduction and external links

The example is based on SSLExampleCode but is simplified and is put in operational status.

The example connection goes to

Necessary libraries

To operate with CSecureSocket class we need to include this header files:

#include <in_sock.h>
#include <SecureSocket.h>

And to add this libraries to .mmp file:

LIBRARY insock.lib
LIBRARY securesocket.lib
LIBRARY esock.lib

Connection process

The connection is organized as Active Object. In ConnectL() method the RSocket socket is opened and connected:

void CSecureSocketCore::ConnectL()
_LIT( KIPAddress, "");
TInetAddr addr;
TUint32 aAddr;
iState = EMakingSecureConnection;
if ( addr.Input( KIPAddress ) == KErrNone )
// server name is already a valid ip address
aAddr = addr.Address();
iAddress.SetPort( iPort );
iAddress.SetAddress( aAddr );
iAddress.SetFamily( KAfInet );
// Open a TCP socket
User::LeaveIfError( iSocket.Open( iSocketServer,
KProtocolInetTcp ) );
// Initiate socket connection
iSocket.Connect( iAddress, iStatus );

Then MakeSecureConnectionL() method accomplishes a handshake with the server:

Contrib 018 i01 handshake.jpg

void CSecureSocketCore::MakeSecureConnectionL()
iTlsSocket = CSecureSocket::NewL( iSocket, _L("SSL3.0"));
// start the handshake
iTlsSocket->StartClientHandshake( iStatus );

The page request goes is as follows:

void CSecureSocketCore::MakePageRequestL()
_LIT8( KPage , "");
// Create a GET request
iSndBuffer+=KSimpleGet; // "GET "
iSndBuffer+=KNewLine; // "\n"
// Send the request
iTlsSocket->Send( iSndBuffer, iStatus, iBytesSent );

Following two functions are retrieving the server response:


Contrib 018 i02 output.gif

Download the example source code

The example is available as Carbide C++ project. To know how to import project from Zip look here. Download Zip file from here:

The main implementation is in the SecureSocketCore.cpp file

This page was last modified on 30 May 2013, at 04:32.
37 page views in the last 30 days.