Mongoose WebSocket Client - dns fails to resolve

I’m building a Windows Win32 ‘C’ client application (Visual Studio 2017) using the Mongoose Websockets library - To test the library I’m attempting to connect to ws://echo.websocket.org and then send a message/get a response.

I’ve cloned the mongoose GitHub repository, and have copied the mongoose.c, and mongoose.h files, and added to my project, and have copied the echo sample client code for my main application.

I turned on debug messages (MG_ENABLE_DEBUG), and have left the other settings in the header file as default (I will want to turn off some of the features later).

I’m seeing connection error -1, and failed to resolve ‘echo.websocket.org’, on server 8.8.8.8.

Is this a known issue, and thoughts on how to resolve?

output from my app is below:

mongoose.c:4130 012FFC50 using select()
mongoose.c:2617 ==================================
mongoose.c:2618 init mgr=012FFC50
tcp://echo.websocket.org:80
mongoose.c:8753 ws://echo.websocket.org/ use_ssl? 0 tcp://echo.websocket.org:80
mongoose.c:12212 echo.websocket.org 1 012FF660
mongoose.c:3161 016E85D8 udp://8.8.8.8:53
mongoose.c:2418 012FFC50 016E85D8
GET / HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: KQAAACNIAAC+GAAAhGcAAA==

Host: echo.websocket.org

mongoose.c:4046 016E85D8 fd=304 fd_flags=2 nc_flags=0xa rmbl=0 smbl=0
mg_resolve_async_eh: MG_EV_POLL
mongoose.c:3176 016E85D8 udp://8.8.8.8:53 -> 0
mongoose.c:2450 016E85D8 user ev=2 ev_data=012FF3E8 flags=0x2 rmbl=0 smbl=0
mongoose.c:12123 ev=2 user_data=016E9248
mg_resolve_async_eh: MG_EV_CONNECT
mongoose.c:11682 echo.websocket.org 1
mongoose.c:2472 016E85D8 after user flags=0x2 rmbl=0 smbl=36
mongoose.c:3133 016E85D8 -> 36 bytes
mongoose.c:2450 016E85D8 user ev=4 ev_data=012FF3D8 flags=0x2 rmbl=0 smbl=0
mongoose.c:12123 ev=4 user_data=016E9248
mg_resolve_async_eh: MG_EV_SEND
mongoose.c:2472 016E85D8 after user flags=0x2 rmbl=0 smbl=0
mongoose.c:4098 016E85D8 after fd=304 nc_flags=0x2 rmbl=0 smbl=0
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mongoose.c:11682 echo.websocket.org 1
mongoose.c:4046 016E85D8 fd=304 fd_flags=2 nc_flags=0x2 rmbl=0 smbl=36
mg_resolve_async_eh: MG_EV_POLL
mongoose.c:3133 016E85D8 -> 36 bytes
mongoose.c:2450 016E85D8 user ev=4 ev_data=012FF3D8 flags=0x2 rmbl=0 smbl=0
mongoose.c:12123 ev=4 user_data=016E9248
mg_resolve_async_eh: MG_EV_SEND
mongoose.c:2472 016E85D8 after user flags=0x2 rmbl=0 smbl=0
mongoose.c:4098 016E85D8 after fd=304 nc_flags=0x2 rmbl=0 smbl=0
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mg_resolve_async_eh: MG_EV_POLL
mongoose.c:11682 echo.websocket.org 1
mongoose.c:4046 016E85D8 fd=304 fd_flags=2 nc_flags=0x2 rmbl=0 smbl=36
mg_resolve_async_eh: MG_EV_POLL
mongoose.c:4098 016E85D8 after fd=304 nc_flags=0x802 rmbl=0 smbl=36
mongoose.c:4046 016E85D8 fd=304 fd_flags=2 nc_flags=0x802 rmbl=0 smbl=36
mongoose.c:2450 016E85D8 user ev=5 ev_data=00000000 flags=0x802 rmbl=0 smbl=36
mongoose.c:12123 ev=5 user_data=016E9248
mg_resolve_async_eh: MG_EV_CLOSE
mongoose.c:12183 Failed to resolve ‘echo.websocket.org’, server 8.8.8.8
mongoose.c:2450 016E8898 proto ev=2 ev_data=012FEF88 flags=0x100 rmbl=0 smbl=157
mongoose.c:2450 016E8898 user ev=2 ev_data=012FEF88 flags=0x100 rmbl=0 smbl=157
– Connection error: -1
mongoose.c:2472 016E8898 after user flags=0x100 rmbl=0 smbl=157
mongoose.c:2472 016E8898 after proto flags=0x100 rmbl=0 smbl=157
mongoose.c:2450 016E8898 proto ev=5 ev_data=00000000 flags=0x100 rmbl=0 smbl=157
mongoose.c:2450 016E8898 user ev=5 ev_data=00000000 flags=0x100 rmbl=0 smbl=157
mongoose.c:2472 016E8898 after user flags=0x100 rmbl=0 smbl=157
mongoose.c:2472 016E8898 after proto flags=0x100 rmbl=0 smbl=157
mongoose.c:2472 016E85D8 after user flags=0x802 rmbl=0 smbl=36
mongoose.c:2633 012FFC50

Note that ths dns resolve issue doesn’t appear to be WebSocket specific, using the code below causes the same dns error.

mg_mgr_init(&mgr, NULL);

const char *dnsURL = "http://websocket.org/"; 
mg_connect_http(&mgr, ev_handler, dnsURL, NULL, NULL);

while (!s_done) {
	mg_mgr_poll(&mgr, 100);
}
mg_mgr_free(&mgr);

The 8.8.8.8 is a google’s DNS server.
Maybe your network blocks UDP traffic to it?

This is how I test it manually on a UNIX shell:

$ dig @8.8.8.8 echo.websocket.org
...
echo.websocket.org.     4       IN      A       174.129.224.73

As you can see, the dig UNIX utility is able to resolve the name using that server. You could try the same.