[Libwebsockets] Unable to communicate with node server over Websocket
anders at brander.dk
Wed Aug 20 13:51:07 CEST 2014
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 token
from body and then initiate websocket request using said token.
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);
/* 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...
More information about the Libwebsockets