Namespaces
Variants
Actions

Sample QSslSocket Example

Jump to: navigation, search
Article Metadata

Tested with
Devices(s): Emulator / desktop / device

Compatibility
Platform(s): All Qt Supported

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 04:18.
114 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved