#ifndef HTTPSERVER_H
#define HTTPSERVER_H
#include <QtNetwork>
{
Q_OBJECT
public:
HttpServer();
~HttpServer();
protected:
void incomingConnection (int socket);
protected slots:
void gotHeaderData();
void ready();
void sslErrors( const QList<QSslError> &errors );
void gotDisconnected();
private:
bool mySSLFlag;
};
#endif
#ifndef HTTPSERVER_H
#define HTTPSERVER_H
#include <QtNetwork>
class QTcpServer;
class HttpServer : public QTcpServer
{
Q_OBJECT
public:
HttpServer();
~HttpServer();
protected:
void incomingConnection (int socket);
protected slots:
void gotHeaderData();
void ready();
void sslErrors( const QList<QSslError> &errors );
void gotDisconnected();
private:
bool mySSLFlag;
};
#endif
To copy to clipboard, switch view to plain text mode
#include <stdlib.h>
//My Include
#include "HttpServer.h"
HttpServer::HttpServer()
{
mySSLFlag = true;
//Create a new server, and have it listen for any http requests on port 7072
{
fprintf(stderr, "Unable to start the server %s", this->errorString().toLatin1());
return;
}
printf("The server is running on port %d\n", this->serverPort());
}
HttpServer::~HttpServer()
{
}
void HttpServer::incomingConnection(int socketDescriptor)
{
QSslSocket *serverSocket = new QSslSocket(this);
if (serverSocket->setSocketDescriptor(socketDescriptor))
{
connect(serverSocket, SIGNAL(encrypted()), this, SLOT(ready()));
connect(serverSocket, SIGNAL(disconnected()),
this, SLOT(gotDisconnected()));
connect(serverSocket, SIGNAL(readyRead()),
this, SLOT(gotHeaderData()));
connect( serverSocket, SIGNAL(sslErrors(QList<QSslError>)),
this, SLOT(sslErrors(QList<QSslError>)) );
serverSocket->setLocalCertificate( "ssl.pem" );
serverSocket->setPrivateKey( "ssl.pem" );
serverSocket->startServerEncryption();
}
else
{
delete serverSocket;
}
}
void HttpServer::gotDisconnected()
{
qDebug("Ooops...\n");
sender()->deleteLater();
}
void HttpServer::ready()
{
qDebug("READY! \n");
}
void HttpServer::sslErrors( const QList<QSslError> &errors )
{
foreach( const QSslError &error, errors )
{
switch( error.error() )
{
case QSslError::NoPeerCertificate: dynamic_cast<QSslSocket *>(sender())->ignoreSslErrors(); break;
default:
qWarning( "CLIENT SSL: error %s", qPrintable(error.errorString()) );
disconnect(); return;
}
}
}
void HttpServer::gotHeaderData()
{
/*code*/
}
#include <stdlib.h>
//My Include
#include "HttpServer.h"
HttpServer::HttpServer()
{
mySSLFlag = true;
//Create a new server, and have it listen for any http requests on port 7072
if (!listen(QHostAddress::Any, 7072))
{
fprintf(stderr, "Unable to start the server %s", this->errorString().toLatin1());
return;
}
printf("The server is running on port %d\n", this->serverPort());
}
HttpServer::~HttpServer()
{
}
void HttpServer::incomingConnection(int socketDescriptor)
{
QSslSocket *serverSocket = new QSslSocket(this);
if (serverSocket->setSocketDescriptor(socketDescriptor))
{
connect(serverSocket, SIGNAL(encrypted()), this, SLOT(ready()));
connect(serverSocket, SIGNAL(disconnected()),
this, SLOT(gotDisconnected()));
connect(serverSocket, SIGNAL(readyRead()),
this, SLOT(gotHeaderData()));
connect( serverSocket, SIGNAL(sslErrors(QList<QSslError>)),
this, SLOT(sslErrors(QList<QSslError>)) );
serverSocket->setLocalCertificate( "ssl.pem" );
serverSocket->setPrivateKey( "ssl.pem" );
serverSocket->startServerEncryption();
}
else
{
delete serverSocket;
}
}
void HttpServer::gotDisconnected()
{
qDebug("Ooops...\n");
sender()->deleteLater();
}
void HttpServer::ready()
{
qDebug("READY! \n");
}
void HttpServer::sslErrors( const QList<QSslError> &errors )
{
foreach( const QSslError &error, errors )
{
switch( error.error() )
{
case QSslError::NoPeerCertificate: dynamic_cast<QSslSocket *>(sender())->ignoreSslErrors(); break;
default:
qWarning( "CLIENT SSL: error %s", qPrintable(error.errorString()) );
disconnect(); return;
}
}
}
void HttpServer::gotHeaderData()
{
/*code*/
}
To copy to clipboard, switch view to plain text mode
Bookmarks