在应用程序启动之前,我需要检查 Internet 连接是否已启动。做这个的最好方式是什么?我正在使用振动。
我写了下一个代码:
import std.stdio;
import std.string;
import std.conv;
import vibe.d;
import vibe.core.log;
import vibe.http.client;
import vibe.stream.operations;
import vibe.core.driver;
void main()
{
HTTPClientResponse res = requestHTTP("http://www.example.org/");
try
{
if (res.statusCode != 200)
{
logInfo("Check Internet connection, and try again!");
logInfo("Server response is: " ~ to!string(res.statusCode));
}
else
{
logInfo("All ok");
}
}
catch (Exception e)
{
writeln(e.msg);
}
}
但是,如果我在没有 Internet 连接的情况下运行它,我会收到错误:
core.exception.AssertError@core.d(1177): No events registered, exiting event loop.