Copyright ©

Mongoose OS Forum

ATTENTION! This forum has moved to:

Do not post any new messages.

Websocket (beginner) question


I'm trying to start a websocket connection - for the beginning with a listening port following the given example found in

static const char *s_http_port = "8000";
struct mg_mgr mgr;
struct mg_connection *nc;

mg_mgr_init(&mgr, NULL);
nc = mg_bind(&mgr, s_http_port, ev_handler);

while ()
mg_mgr_poll(&mgr, );


but right after start I continuously get the message:

mg_tun_client_handler Cannot connect to the tunnel dispatcher: 111

Any idea what I'm doing wrong?



  • sorry - forgot the version - it's mongoose 6.7

  • Are you trying to use pure Mongoose networking only, or within the framework of Mongoose-OS?

    I followed the path of trying to use the Mongoose networking constructs, the same as you show, within the Mongoose-OS frame work on ESP32.
    That did not work well. If you use Mongoose-OS, it all becomes simpler. You get Websocket for free by using the OS.

    The simplest route is to use RPC. This is sort of already "hooked" to Websocket. This is the case when using a device as a "client". What I mean is the device is remotely controlled via Websocket/RPC.
    I think it is more complicated if you want a client which returns acknowledgements, or a Websocket server. For the server, I fell back to C code and an event handler. Even that can probably be done via RPC.

  • Thanks for your answer

    Are you trying to use pure Mongoose networking only, or within the framework of Mongoose-OS?

    Hm, don't know if I got that right - I'm using mongoose.h/.c as a http-client (which works) and now I'd like to try websockets - and given error occurs.
    I'm using plain Linux with any framework, etc...

  • sorry - without any framework :-)

  • SergeySergey Dublin, Ireland

    @codewarrior71 are you able to build and run the example?

  • Hi Sergey,
    the code above is only an extract - I just wanted to show the steps I did - but yes - my code is runnable - that's where I got the output "mg_tun_client_handler Cannot connect to the tunnel dispatcher: 111" from...

  • SergeySergey Dublin, Ireland

    I can hardly figure out what is wrong :)

    Here is my transcript:

    ~/src/$ make
    cc websocket_chat.c ../../mongoose.c -o websocket_chat -g -W -Wall -Werror -I../.. -Wno-unused-function  -DMG_ENABLE_FILESYSTEM=1 -pthread
    ~/src/$ ./websocket_chat
    Started on port 8000

    Everything works as expected. If you point me to the way to reproduce, I'll do it!

  • Hi Sergey,
    you showed me the point I was to blind to see (arghhh) - thanks :-) The Problem was that I used "ws://:" instead of simply the PORT in the mg_bind-function.

  • ws://IP:PORT

  • @codewarrior71 , I am curious, are you using mos tool or make and gcc or some other method to get this compiled and working? Device you are using, ESP32 or other?

Sign In or Register to comment.