2 aa1807a aa1807a 于 2015.06.19 14:09 提问

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
oyljerry   Ds   Rxr 2015.06.19 14:39

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

aa1807a
aa1807a   2015.06.19 15:03

才发现 例题的server里面 加了个 QMAKE_CXXFLAGS += -std=c++11......

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
ssh连接提示 "Connection closed by remote host"
原文地址:http://www.lao8.org/article_1319/ssh ssh连接提示 "Connection closed by remote host" 2014年04月10日 09:22 by:老修分类:网站技术 -> linux服务器配置 正文我来说两句 导读: 在用 ssh secureshell slient 远程连接的时候提示 ""Conn
使用命令登录不是默认端口的ftp server(Connection closed by remote host的原因)
如果登录的ftp server不是默认端口,在命令行中输入:C:/Documents and Settings/yourname>ftp 172.28.1.1Connected to 172.28.93.248.Connection closed by remote host.C:/Documents and Settings/yourname>ftp 172.28.1.1:8
Linux expect问题集:ssh_exchange_identification: Connection closed by remote host
Linux expect应用实例
Qtcpsocket The remote host closed the connection
来源:http://bbs.csdn.net/topics/390821598 C/S程序,tcp连接。 本来都是用winsock写的。 server端对我来说是黑盒的, 现在想把客户端改成用qt实现(qtcpsocket)。 现在的问题是,连接能够连接上, 但是下面代码 if(!SendDataToEC(&head,sizeof(HEAD)))    {  
ssh_exchange_identification: Connection closed by remote host
花了两个星期。终于搞定ssh_exchange_identification: Connection closed by remote host 走了许多弯路。写解决方法 主要是 /etc/hosts.allow 和 /etc/hosts.deny问题 最好两个都设置一下。因为有些系统是先load hosts.allow 再 load hosts.allow .有些相反。 hosts.allo
ssh/scp:ssh_exchange_identification:Connection closed by remote host的问题
ssh/scp:ssh_exchange_identification:Connection closed by remote host的问题     使用ssh/scp时,出现下列问题:     Java代码     ssh_exchange_identification: Connection closed by remote host     解决办法:   
Remote host closed connection during handshake
https通过TSLv1和TSLv1.2协议通信。jdk1.7默认是TSLv1, 可以支持TSLv1.1,TSLv1.2,jdk1.8默认是TSLv1.2假如服务器端设置是TSLv1.2,而客服端是TSLv1, 访问就会出现Remote host closed connection during handshake的错误.解决办法:强制通过TLSv1.2或TLSv1通信,前提服务端也采用相应协议。...
连接linux ssh连接提示:Connection closed by remote host
导读: Linux 主机最常用的连接方式就是用ssh, 今天在用 ssh secureshell slient 远程连接的时候提示 &quot;Connection closed by remote host&quot; 主机连接关闭, 以前都是可以正常访问的,突然出现这个问题很郁闷. 突然连接不上通常是连接数过多导致的.  解决方法一. 把SSH连接数改大  修改服务器上的这个文件:/etc/ssh/sshd_co...
javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
信息: Retrying request to {s}->https://api.weixin.qq.com:443 2015-07-15 10:08:26 CST ERROR com.sunyard.utils.HTTPUtils 164 execute - 【HTTP操作】 javax.net.ssl.SSLHandshakeException: Remote host closed con
Connection closed by foreign host. Disconnected from remote host
之前在宿舍使用无线网使用时,可以用XShell连接上Linux,如今换到公司的无线网络之后,出现这个问题:      Connection closed by foreign host. Disconnected from remote host 现检查了Linux虚拟机的网络配置,VMware中使用桥接并设置选中了桥接网卡,关闭了内置的防火墙,更改了IP地址并配置在同一网段中,,结