CSecureSocket example
Article Metadata
Code Example
Article
Contents |
Introduction and external links
The example is based on SSLExampleCode but is simplified and is put in operational status.
The example connection goes to http://www.mozilla.org/
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, " 63.245.209.11");
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,
KAfInet,
KSockStream,
KProtocolInetTcp ) );
// Initiate socket connection
iSocket.Connect( iAddress, iStatus );
SetActive();
}
}
Then MakeSecureConnectionL() method accomplishes a handshake with the server:
void CSecureSocketCore::MakeSecureConnectionL()
{
iTlsSocket = CSecureSocket::NewL( iSocket, _L("SSL3.0"));
iTlsSocket->FlushSessionCache();
// start the handshake
iTlsSocket->StartClientHandshake( iStatus );
}
The page request goes is as follows:
void CSecureSocketCore::MakePageRequestL()
{
User::LeaveIfError(iStatus.Int());
_LIT8( KPage , "http://www.mozilla.org/");
// Create a GET request
iSndBuffer+=KSimpleGet; // "GET "
iSndBuffer+=KPage();
iSndBuffer+=KNewLine; // "\n"
// Send the request
iTlsSocket->Send( iSndBuffer, iStatus, iBytesSent );
}
Following two functions are retrieving the server response:
GetServerResponseL()
ReadServerResponseL()
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: File:WikiSecureSocketEx.zip
The main implementation is in the SecureSocketCore.cpp file




(no comments yet)