-->
Page 1 of 1

Websockets pointer outside callbacks

PostPosted: Thu Feb 02, 2017 6:11 pm
by Piotr Wilga
Hello,

I'm wondering how can I send message to the particular websocket outside callback functions. I tried to do the following:

Code: Select allwebsck.h

Websock *wsk;

websck.c

void myWebsocketConnect(Websock *ws) {

   ws->recvCb=myWebsocketRecv;
   cgiWebsocketSend( ws, "Hi, Websocket!", 14, WEBSOCK_FLAG_NONE);

   wsk = ws;
}


and in one of the tasks fuctioncs try to send message via cgiWebsocketSend:

Code: Select all#include "websck.h"

user_main(os_event_t *event) {
   cgiWebsocketSend( wsk, buffer, os_strlen(buffer), WEBSOCK_FLAG_NONE);
}


Unfortunately cgiWebsocketSend always return 1 regardless how many bytes are in the buffer. Nothing happens, but spontaneous reset after a while

Re: Websockets pointer outside callbacks

PostPosted: Mon Feb 13, 2017 3:50 pm
by Piotr Wilga
For someone who might be interested. Following code works just fine:

Code: Select allhttpdConnSendStart(wsk->conn);
cgiWebsocketSend( wsk, buffer, os_strlen(buffer), WEBSOCK_FLAG_NONE);
httpdConnSendFinish(wsk->conn);