×
Namespaces

Variants
Actions

Sample QSslSocket Example

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Emulator / desktop / device
Compatibility
Platform(s): All Qt Supported
Symbian
Article
Keywords: QSslSocket
Created: skumar_rao (26 Nov 2010)
Last edited: hamishwillee (11 Oct 2012)

Description

The QSslSocket class provides an SSL encrypted socket for both clients and servers.QSslSocket establishes a secure, encrypted TCP connection you can use for transmitting encrypted data. It can operate in both client and server mode, and it supports modern SSL protocols.

SSL encryption operates on top of the existing TCP stream after the socket enters the ConnectedState. There are two simple ways to establish a secure connection using QSslSocket: With an immediate SSL handshake, or with a delayed SSL handshake occurring after the connection has been established in unencrypted mode. The most common way to use QSslSocket is to construct an object and start a secure connection by calling connectToHostEncrypted(). This method starts an immediate SSL handshake once the connection has been established.

#include <QApplication>
#include <QSslSocket>
#include <QDebug>
 
int main( int argc, char **argv )
{
QApplication app( argc, argv );
 
QSslSocket socket;
socket.connectToHostEncrypted( "bugs.kde.org", 443 );
 
if ( !socket.waitForEncrypted() ) {
qDebug() << socket.errorString();
return 1;
}
 
socket.write( "GET / HTTP/1.1\r\n" \
"Host: bugs.kde.org\r\n" \
"Connection: Close\r\n\r\n" );
while ( socket.waitForReadyRead() ) {
qDebug() << socket.readAll().data();
};
 
qDebug() << "Done";
 
return 0;
}

More information you can find in http://doc.qt.nokia.com/4.7/qsslsocket.html

--skumar_rao 19:19, 26 November 2010 (UTC)

This page was last modified on 11 October 2012, at 01:18.
149 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×