[Libwebsockets] Issue sending data

Andy Green andy at warmcat.com
Mon Jan 2 23:28:58 CET 2017


On Mon, 2017-01-02 at 21:50 +0000, Derrill Vezina wrote:
> I am currently using libwebsockets to act as a websocket server from
> the most up to date git repository master branch with a very simple
> implementation to get things up and running (this is my first time
> using the library).
>  
> My goal is simply to send a packet out every 2 seconds, and print out
> any data received by any client. After 2 seconds, I try to call
> lws_callback_on_writable_all_protocol() to write data and the
> callback is not firing for LWS_CALLBACK_SERVER_WRITEABLE or
> LWS_CALLBACK_CLIENT_WRITEABLE.

That's because your ws connection is connected using "client-protocol", 
but your code says

 lws_callback_on_writable_all_protocol(context, protocols);

that's saying ask for a callback when anybody connected with
protocols[0] becomes writable.  You want

 lws_callback_on_writable_all_protocol(context, &protocols[1]);

since "client-protocol" is the second guy in the protocols[] array.

Otherwise it looks good already.

-Andy

> I have attached main.cpp code I am currently using and the test .html
> page that I grabbed from the net. After a connection is established,
> the callback on writeable is not getting fired. Is there something I
> am missing here with my protocol configuration that someone could
> help me with that would make it so I am unable to send data?
>  
> This is my console output:
>  
> [2017/01/02 16:45:03:1580] NOTICE: Initial logging level 7
> [2017/01/02 16:45:03:1581] NOTICE: Libwebsockets version: 2.1.0 dvez@
> ubuntu-v2.0.0-217-g58a26eb
> [2017/01/02 16:45:03:1581] NOTICE: IPV6 not compiled in
> [2017/01/02 16:45:03:1581] NOTICE: libev support not compiled in
> [2017/01/02 16:45:03:1581] NOTICE: libuv support not compiled in
> [2017/01/02 16:45:03:1581] NOTICE:  Threads: 1 each 65536 fds
> [2017/01/02 16:45:03:1585] NOTICE:  mem: platform fd map: 524288
> bytes
> [2017/01/02 16:45:03:1585] NOTICE:  Compiled with OpenSSL support
> [2017/01/02 16:45:03:1585] NOTICE:  SSL disabled: no
> LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT
> [2017/01/02 16:45:03:1585] NOTICE: Creating Vhost 'default' port
> 4500, 2 protocols, IPv6 off
> [2017/01/02 16:45:03:1588] NOTICE:  Listening on port 4500
> [2017/01/02 16:45:03:1588] NOTICE:  mem: per-conn:          568 bytes
> + protocol rx buf
> [2017/01/02 16:45:03:1588] NOTICE:  canonical_hostname = ubuntu
> Websocket server started and is listening
> [2017/01/02 16:45:03:1599] NOTICE: lws_protocol_init
> Websocket protocol initialized
> [2017/01/02 16:45:04:2919] NOTICE: Accepted wsi 0x18dfb90 to context
> 0x18d6760, tsi 0
> Websocket session started
> Data received: Echo
> Timer expired
> Websocket has ended session
> [2017/01/02 16:47:17:5549] NOTICE: lws_context_destroy: ctx 0x18d6760
> Websocket protocol destroyed
> [2017/01/02 16:47:17:5555] NOTICE: lws_context_destroy2: ctx
> 0x18d6760
>  
> Best regards,
>  
> DV
> Websocket Server Test
> View console in developer tools
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> https://libwebsockets.org/mailman/listinfo/libwebsockets



More information about the Libwebsockets mailing list