[Libwebsockets] Send data to callback to write on websocket

Iker Perez de Albeniz iker.perez at fon.com
Wed Jul 16 12:28:58 CEST 2014


Hi,

I am maquing a simple client using text-echo example, as i have seen on the
code when libwebsocket_callback_on_writable_all_protocol is calledd  whet
client writable, callback function do this:

----------------------------------

case LWS_CALLBACK_CLIENT_WRITEABLE:
/* we will send our packet... */
pss->len = sprintf((char *)&pss->buf[LWS_SEND_BUFFER_PRE_PADDING], "hello
from libwebsockets-test-echo client pid %d index %d", getpid(),
pss->index++);
 lwsl_notice("Client TX: %s", &pss->buf[LWS_SEND_BUFFER_PRE_PADDING]);
n = libwebsocket_write(wsi, &pss->buf[LWS_SEND_BUFFER_PRE_PADDING],
pss->len, LWS_WRITE_TEXT);
if (n < 0) {
lwsl_err("ERROR %d writing to socket, hanging up\n", n);
return -1;
}
if (n < (int)pss->len) {
lwsl_err("Partial write\n");
return -1;
}
break;

----------------------------------

i mean, stores hardcoded ("hello from...") data to send on pss->buff and
writes it on websocket..

my question is, is there any example about how to write data from an other
thread/process/queue or pile..?? I mean..

----------------------------------

case LWS_CALLBACK_CLIENT_WRITEABLE:

         pss->buf = call_function_dat_gets_data_from_queue_or_pile();
         lwsl_notice("Client TX: %s",
&pss->buf[LWS_SEND_BUFFER_PRE_PADDING]);
n = libwebsocket_write(wsi, &pss->buf[LWS_SEND_BUFFER_PRE_PADDING],
pss->len, LWS_WRITE_TEXT);
          ....
          ....

----------------------------------

I want to know if there is any proper way to do this or even if the library
has any function to do this (i haven't found searching doc and google).

Regards.


-- 

Iker Perez de Albeniz
Senior R&D Engineer / Technical Lead
Fon Labs
skype: iker.perez.fon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://libwebsockets.org/pipermail/libwebsockets/attachments/20140716/18edb0bd/attachment.html>


More information about the Libwebsockets mailing list