[Libwebsockets] Unable to communicate with node server over Websocket
andy at warmcat.com
Wed Aug 20 14:03:36 CEST 2014
On 20 August 2014 19:51:07 GMT+08:00, Anders Brander <anders at brander.dk> wrote:
>On Wed, 2014-08-20 at 16:59 +0530, sthustfo wrote:
>> I was of the opinion that in order to connect to the server, you need
>> to have a path like - "/socket.io/1/websocket/RJmiyNAyu1PZFRp5WiLn".
>> Where "RJmiyNAyu1PZFRp5WiLn" is an id that is returned by the nodejs
>> (socket.io) server in response to GET request sent over HTTP (xhr).
>I used another library to do the initial HTTP GET request, extract
>from body and then initiate websocket request using said token.
Wuh that shouldn't be necessary, lws should have enough pieces to do it all.
>Something like this for an OLD version of libwebsockets and libsoup:
> /* Connect to socket.io server */
> SoupSession *session = soup_session_sync_new();
> url = g_strdup_printf("http://%s/socket.io/1", host);
> SoupMessage *msg = soup_message_new("GET", url);
> soup_session_send_message(session, msg);
> /* We should have a response body in the form of
> content = g_strsplit(msg->response_body->data, ":", 4);
> session_id = content;
> heartbeat_timeout = atoi(content);
> path = g_strdup_printf("/socket.io/1/websocket/%s", session_id);
> remote->priv->client = libwebsocket_client_connect(
> /* Setup heartbeat */
>Maybe this can help somebody...
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org
More information about the Libwebsockets