[Libwebsockets] Unable to communicate with node server over Websocket

Andy Green 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:
>Hi,
>
>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.

Wuh that shouldn't be necessary, lws should have enough pieces to do it all.

-Andy

>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);
>	g_free(url);
>
>	soup_session_send_message(session, msg);
>
>	/* We should have a response body in the form of
>	 *
>"session_id:heartbeat_timeout:connection_closing_timeout:supported_transports"
>	 */
>
>	content = g_strsplit(msg->response_body->data, ":", 4);
>	session_id = content[0];
>	heartbeat_timeout = atoi(content[1]);
>
>	path = g_strdup_printf("/socket.io/1/websocket/%s", session_id);
>	g_strfreev(content);
>
>	remote->priv->client = libwebsocket_client_connect(
>		remote->priv->context,
>		host,
>		80,
>		0,
>		path,
>		"",
>		"",
>		NULL,
>		0);
>
>	/* Setup heartbeat */
>
>	...
>
>Maybe this can help somebody...
>
>/Anders
>_______________________________________________
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org
>http://ml.libwebsockets.org/mailman/listinfo/libwebsockets




More information about the Libwebsockets mailing list