Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

重启服务端后,客户端显示重连成功,但是服务端并未显示有客户端连上来。 #93

Open
zwny520 opened this issue Jun 18, 2021 · 1 comment

Comments

@zwny520
Copy link

zwny520 commented Jun 18, 2021

客户端代码:

#include "handy/ssl-conn.h"

int main(int argc, const char* argv[]) {
using namespace handy;
Logger::getLogger().setLogLevel(Logger::LTRACE);
EventBase ebase;
Signal::signal(SIGINT, [&]{ ebase.exit(); });
SSLConn::setSSLCertKey("server.pem", "server.pem");
TcpServer ss(&ebase);
int r = ss.bind("0.0.0.0", 1002);
exitif(r, "bind failed %d %s", errno, strerror(errno));
ss.onConnCreate([]{ return TcpConnPtr(new SSLConn); });
ss.onConnRead([](const TcpConnPtr& con) {
con->send(con->getInput());
con->getInput().clear();
});
ebase.loop();
return 0;
}

服务端代码:

#include "handy/ssl-conn.h"

int main(int argc, const char* argv[]) {
Logger::getLogger().setLogLevel(Logger::LTRACE);
EventBase ebase;
Signal::signal(SIGINT, [&]{ ebase.exit(); });
SSLConn::setSSLCertKey("server.pem", "server.pem");
TcpServer ss(&ebase);
int r = ss.bind("0.0.0.0", 1002);
exitif(r, "bind failed %d %s", errno, strerror(errno));
ss.onConnCreate([]{ return TcpConnPtr(new SSLConn); });
ss.onConnRead([](const TcpConnPtr& con) {
con->send(con->getInput());
con->getInput().clear();
});

TcpServer ts(&ebase);
r = ts.bind("0.0.0.0", 1003);
exitif(r, "bind failed %d %s", errno, strerror(errno));
ts.onConnRead([](const TcpConnPtr& con) {
    con->send(con->getInput());
    con->getInput().clear();
});
ebase.loop();
return 0;

}

问题大致的原因是服务端关掉重启后,服务端的SSlconn已经重新new了,但是客户端的sslconn还是原来的,客户重连上来虽然显示成功了,但并没有重新握手。也就导致服务端收不到有连接进来的消息。

@yedf2
Copy link
Owner

yedf2 commented Jun 18, 2021

您这边客户端需要处理好连接断开的情况。handy-ssl里的例子主要是演示ssl连接的基本功能,没包括断开重新创建对象并连接这部分

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants