此篇稍為記錄一下在C上面時做websocket時遇到的問題...
---
(a) callback function
return 0;
之前不小心return ;造成websocket的connection都無法建立
---
(b)libwebsocket_write
想要將資料寫出去必須使用libwebsocket_write的函式回傳
下面來個簡單的範例!
char *text = "Hello World!"; int len = strlen (text) + 1; unsigned char *buf = malloc(LWS_SEND_BUFFER_PRE_PADDING + len + LWS_SEND_BUFFER_POST_PADDING); /* copy string including terminating NUL */ memcpy (buf + LWS_SEND_BUFFER_PRE_PADDING, text, len ); libwebsocket_write(wsi, buf + LWS_SEND_BUFFER_PRE_PADDING, len, LWS_WRITE_TEXT); free(buf);
沒有留言:
張貼留言