Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

Websocket (beginner) question

Hi,

I'm trying to start a websocket connection - for the beginning with a listening port following the given example found in
https://github.com/cesanta/mongoose/blob/master/examples/websocket_chat/websocket_chat.c

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
short:
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);
mg_set_protocol_http_websocket(nc);

while ()
{
mg_mgr_poll(&mgr, );
}

mg_mgr_free(&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?

Thanks

Comments

  • 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/cesanta.com/mongoose/examples/websocket_chat$ make
    cc websocket_chat.c ../../mongoose.c -o websocket_chat -g -W -Wall -Werror -I../.. -Wno-unused-function  -DMG_ENABLE_FILESYSTEM=1 -pthread
    ~/src/cesanta.com/mongoose/examples/websocket_chat$ ./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.

  • @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.