fix:修正当没有找到local IP时的崩溃问题。

This commit is contained in:
taynpg 2025-02-05 11:00:05 +08:00
parent 8307a50f16
commit f19b1e3f4d

View File

@ -25,8 +25,9 @@ bool CTcpServer::start(unsigned short port)
{
asio::ip::tcp::resolver resolver(io_context_);
asio::ip::tcp::resolver::query query(asio::ip::host_name(), "");
asio::ip::tcp::resolver::iterator it = resolver.resolve(query);
try {
auto it = resolver.resolve(query);
mpdebug("Here are the local IP addresses you may use.");
mpdebug("===========================================");
int i = 1;
@ -37,6 +38,10 @@ bool CTcpServer::start(unsigned short port)
++i;
}
mpdebug("===========================================");
} catch (const std::exception& e) {
mpwarn("{}", e.what());
mpinfo("will not show local IP.");
}
asio::ip::tcp::endpoint endpoint(asio::ip::tcp::v4(), port);
try {