I'm developing a simple websocket server on Linux using libwebsocket lib.
I need to send an init packet on established event for every client connection.
If I use
memcpy( p, "init", 4);
lws_write(wsi, p, 4, LWS_WRITE_TEXT);
in
case LWS_CALLBACK_ESTABLISHED:
I receive the error
[2018/07/31 18:50:15:5451] ERR:
[2018/07/31 18:50:15:5451] ERR: 0000: 81 04 69 6E 69 74 ..init
[2018/07/31 18:50:15:5451] ERR:
[2018/07/31 18:50:15:5451] ERR: ** 0x564b10ce5170: vh: default, prot: lws-minimal, role ws: Illegal back-to-back write of 6 detected...
From the documentation I read that I cannot recall lws_write
in this phase but don't understand how to prepare data for the LWS_CALLBACK_SERVER_WRITEABLE
phase (and then call lws_callback_on_writable(wsi);
..).
Why the error reports 6 bytes when I lws-write 4 bytes?