qt qsslsocket linux,Qt与QSslSocket没有正确连接

我有一个与QTcpSocket一起工作的客户端 - 服务器应用程序。现在我想使用加密的SSL连接,因此我试图切换到QSslSocket。但是我无法建立与服务器的连接。 这里是为客户端的代码:Qt与QSslSocket没有正确连接

ConnectionHandler::ConnectionHandler(QString ip, int port, QObject *parent) : QObject(parent) {

// connect(this->socket, SIGNAL(connected()), this, SLOT(connected()));

connect(this->socket, SIGNAL(disconnected()), this, SLOT(disconnected()));

connect(this->socket, SIGNAL(readyRead()), this, SLOT(readyRead()));

connect(this->socket, SIGNAL(encrypted()), this, SLOT(encryptedReady()));

connect(this->socket, SIGNAL(sslErrors(const QList &)), this, SLOT(SSLerrorOccured(const QList &)));

connect(this->socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)));

connect(this->socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));

this->ip = ip;

this->port = port;

}

void ConnectionHandler::socketStateChanged(QAbstractSocket::SocketState state) {

qDebug() << state;

}

void ConnectionHandler::socketError(QAbstractSocket::SocketError) {

qDebug() << this->socket->errorString();

}

void ConnectionHandler::encryptedReady() {

qDebug() << "READY";

}

void ConnectionHandler::SSLerrorOccured(const QList &) {

qDebug() << "EEROR";

}

void ConnectionHandler::connectToServer() {

// this->socket->connectToHost(this->ip, this->port);

this->socket->connectToHostEncrypted(this->ip, this->port);

if (!this->socket->waitForConnected(5000)) {

this->socket->close();

this->errorMsg = this->socket->errorString();

}

}

void ConnectionHandler::connected() {

qDebug() << "connected";

this->connectedHostAddress = this->socket->peerAddress().toString();

this->connectionEstablished = true;

this->localIP = this->socket->localAddress().toString();

this->localPort = this->socket->localPort();

}

在这里,一个用于服务器:

ClientHandler::ClientHandler() {

this->socket->setProtocol(QSsl::SslV3);

this->socket->setSocketOption(QAbstractSocket::KeepAliveOption, true);

}

void ClientHandler::run() {

if (!this->fd)

return;

connect(this->socket, SIGNAL(readyRead()), this, SLOT(readyRead()));

connect(this->socket, SIGNAL(disconnected()), this, SLOT(disconnected()), Qt::DirectConnection);

connect(this->socket, SIGNAL(encrypted()), this, SLOT(encryptedReady()));

connect(this->socket, SIGNAL(sslErrors(const QList &)), this, SLOT(sslErrorOccured(const QList &)));

connect(this->socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)));

connect(this->socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));

if (!this->socket->setSocketDescriptor(this->fd)) {

emit error(socket->error());

return;

} else {

connect(this->socket, SIGNAL(encrypted()), this, SLOT(ready()));

this->socket->startServerEncryption();

}

this->peerIP = socket->peerAddress().toString();

QString tmp;

tmp.append(QString("%1").arg(socket->peerPort()));

this->peerPort = tmp;

QHostInfo::lookupHost(this->peerIP, this, SLOT(lookedUp(QHostInfo)));

}

void ClientHandler::socketStateChanged(QAbstractSocket::SocketState state) {

qDebug() << state;

}

void ClientHandler::socketError(QAbstractSocket::SocketError) {

qDebug() << this->socket->errorString();

}

void ClientHandler::setFileDescriptor(int fd) {

this->fd = fd;

}

void ClientHandler::ready() {

qDebug() << "READY";

}

void ClientHandler::sslErrorOccured(const QList &) {

qDebug() << "EEROR";

}

void ClientHandler::encryptedReady() {

qDebug() << "READY";

}

为我接收客户端的输出为:

QAbstractSocket::HostLookupState

QAbstractSocket::ConnectingState

QAbstractSocket::ConnectedState

"The remote host closed the connection"

QAbstractSocket::ClosingState

QAbstractSocket::UnconnectedState

和服务器:

QAbstractSocket::ConnectedState

"Error during SSL handshake: error:1408A0C1:SSL routines:SSL3_GET_CLIENT_HELLO:no shared cipher"

QAbstractSocket::UnconnectedState

有谁知道如何解决这个问题?

2015-10-18

wasp256

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值