aa1807a 2015-06-19 06:09 采纳率: 0%
浏览 3953

QtSsl 出现the remote host closed connection 问题

刚开始学QtSsl 一直找不到什么例子 好不容易看到个 问题是 运行的时候 Client出现了the remote host closed connection的问题 代码如下:
ClientExample::ClientExample(QObject *parent):
QObject(parent)
{

}

void ClientExample::run()
{
QString hostName = "127.0.0.1";
quint16 port = 23333;

QByteArray cert;
QSslSocket client_socket;

QFile file_cert("c:\\Ssl\\bin\\servercert.pem");
if(file_cert.open(QIODevice::ReadOnly))
{
    qDebug()<<"Cert is Ok";
    cert = file_cert.readAll();
    file_cert.close();
}
else
{
    qDebug()<<file_cert.errorString();
}

QSslCertificate ssl_cert(cert);
client_socket.addCaCertificate(ssl_cert);
client_socket.connectToHostEncrypted(hostName, port);
qDebug()<<"Client has connect the IP"<<hostName<<port;

if(client_socket.waitForEncrypted(-1))
{
    qDebug()<<"Connected";
    client_socket.write("Hello, World!");

    if(client_socket.waitForBytesWritten(-1))
        qDebug()<<"Message sent";

    else
        qDebug().nospace()<<"Error: Coulen't send message ("<<qPrintable(client_socket.errorString())<<")";

    while(!client_socket.waitForDisconnected()){

        QThread::msleep(10);
        qDebug()<<"Disconnected";

    }
}

else
{
    qDebug().nospace()<<"Error: Couldn't not establish encrypted connection ("<<qPrintable(client_socket.errorString())<<")";
}

this->deleteLater();
QThread::currentThread()->quit();
qApp->exit();

}

  • 写回答

2条回答 默认 最新

  • oyljerry 2015-06-19 06:39
    关注

    你发起的连接,被server拒绝了,是否允许你连接

    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型