C++ websocketpp asio侦听错误

C++ websocketpp asio侦听错误,c++,boost-asio,websocket++,C++,Boost Asio,Websocket++,我有一个多线程websocketpp服务器。当我退出程序并重新启动时,没有连接任何客户端,因此它可以正常工作 但是,当客户端连接且我退出/重新启动时,程序会抛出此错误 [2017-08-06 15:36:05] [info] asio listen error: system:98 () terminate called after throwing an instance of 'websocketpp::exception' what(): Underlying Transport

我有一个多线程websocketpp服务器。当我退出程序并重新启动时,没有连接任何客户端,因此它可以正常工作

但是,当客户端连接且我退出/重新启动时,程序会抛出此错误

[2017-08-06 15:36:05] [info] asio listen error: system:98 ()
terminate called after throwing an instance of 'websocketpp::exception'
   what():  Underlying Transport Error
Aborted
我相信我有一个正确的断开序列,当我启动退出序列时,我有以下消息(我自己的调试信息)

[2017-08-06 15:35:55] [control] Control frame received with opcode 8
on_close
[2017-08-06 15:35:55] [disconnect] Disconnect close local:[1000] remote:[1000]
Quitting :3
Waiting for thread
asio错误是什么意思?我希望有人以前见过这个,这样我就可以开始排除故障了。谢谢

编辑: 我正在调整stock broadcast_服务器示例,其中

typedef std::map<connection_hdl, connection_data, std::owner_less<connection_hdl> > con_list;
con_list m_connections;
typedef std::map con_list;
con_列表m_连接;
关闭连接的代码

lock_guard<mutex> guard(m_connection_lock);
std::cout << "Closing Server" << std::endl;
con_list::iterator it;
for (it = m_connections.begin(); it != m_connections.end(); ++it)
{
    m_server.close(it->first, websocketpp::close::status::normal, "", ec);
    if (ec)
    {
        std::cout << "> Error initiating client close: " << ec.message() << std::endl;
    }
    m_connections.erase(it->first);
}
lock\u-guard防护装置(m\u-connection\u-lock);

std::cout每当出现
websocketpp::异常时,我首先检查明确使用端点的任何地方,在您的情况下是
m_服务器

例如,您可以在某个地方调用
m\u server.send(…)
。由于您是多线程的,很可能其中一个线程试图利用一个
连接\u hdl
,而另一个线程已经关闭了该连接

在这种情况下,它通常是一个
websocketpp::exception无效状态
。我不确定是否存在
基本传输错误

您可以使用断点来发现罪魁祸首(或者用不同的方法放置一组
cout
序列,并在引发异常之前查看哪个序列被破坏),或者使用try/catch:

try {
    m_server.send(hdl, ...);
    // or
    m_server.close(hdl, ...);
    // or really anything you're trying to do using `m_server`.
} catch (const websocketpp::exception &e) {//by safety, I just go with `const std::exception` so that it grabs any potential exceptions out there.
    std::cout << "Exception in method foo() because: " << e.what() /* log the cause of the exception */ << std::endl;
}
试试看{
m_server.send(hdl,…);
//或
m_服务器关闭(hdl,…);
//或者你想用“m_服务器”做的任何事情。
}catch(constwebsocketpp::exception&e){//出于安全考虑,我只使用'conststd::exception',这样它就可以捕获任何潜在的异常。
std::cout first)
调用
close()
冻结该处理程序中的活动之前



在第二次查看之后,我认为您得到的异常是在使用
m_server.listen(…)进行侦听时抛出的
。尝试用Try/catch将其包围,并放置自定义日志消息。

每当出现
websocketpp::exception
,我首先检查明确使用端点的任何位置,在您的情况下是
m_server

例如,您可以在某个地方调用
m\u server.send(…)
。由于您是多线程的,很可能其中一个线程试图利用一个
连接\u hdl
,而另一个线程已经关闭了该连接

在这种情况下,它通常是
websocketpp::exception无效状态
。我不确定是否存在
底层传输错误

您可以使用断点来发现罪魁祸首(或者用不同的方法放置一组
cout
序列,并在引发异常之前查看哪个序列被破坏),或者使用try/catch:

try {
    m_server.send(hdl, ...);
    // or
    m_server.close(hdl, ...);
    // or really anything you're trying to do using `m_server`.
} catch (const websocketpp::exception &e) {//by safety, I just go with `const std::exception` so that it grabs any potential exceptions out there.
    std::cout << "Exception in method foo() because: " << e.what() /* log the cause of the exception */ << std::endl;
}
试试看{
m_server.send(hdl,…);
//或
m_服务器关闭(hdl,…);
//或者你想用“m_服务器”做的任何事情。
}catch(constwebsocketpp::exception&e){//出于安全考虑,我只使用'conststd::exception',这样它就可以捕获任何潜在的异常。
std::cout first)
调用
close()
冻结该处理程序中的活动之前



在第二次查看之后,我认为您得到的异常是在使用
m_server.listen(…)进行侦听时抛出的
。尝试用Try/catch将其包围,并放置自定义日志消息。

是否正确关闭连接?代码在哪里?@Blacktempel:是的,我使用了github上示例中的代码来关闭连接。我编辑了帖子。是否正确关闭连接?代码在哪里?@Blacktempel:是的,我使用了来自我已经编辑了github上的示例以关闭连接