[Libwebsockets] parameters for libwebsocket_client_connect()

Andy Green andy at warmcat.com
Mon Nov 24 23:23:54 CET 2014

On 24 November 2014 09:29:58 GMT+08:00, "yogeshldeshmukh ." <yogeshldeshmukh at gmail.com> wrote:
>Hi Andy,
>I’m bit confused about parameters for libwebsocket_client_connect()
>If the URL  of webscoket server  is
>(I’m also sending some parameters at the time of connection
>establishment )
>then the parameters to pass will be
>Address  = “ myserver.com"
>Port   =6781
>ssl_connection =1
>path  = ??
>    Websocket path on server      ???

The path is set with the upgrade header, it's meaning is defined by the server.

Many times the path is not meaningful but for example you can send parameters like a session ID here using ?session=xxx

>Host  = ??

This is how HTTP virtual servers work.  Server at IP address may have 20 different websites.  The browser puts the original name the user wrote before DNS here, so the server can select the right virtual server to give him.

If your server doesn't care you don't have to care either.  But if it'll be used on random servers, you should set to "myserver.com" if that's the server name he tried to connect to.

>Origin  =?

This is a security thing for browsers so another IFRAME or somesuch can't fool your browser into making requests to the server for the main page.  Your browser will send the request with Origin=badhacker.com if that was where the IFRAME came from.  The server for yourbank.com can check that Origin is yourbank.com, which is what scripts from the main page will say, or reject it.

Again ws doesn't care, if you and your server don't care about the situation above (can never get an external / advert IFRAME on your page) you don't have to care what you send here.

>Confusions :
>1.  What exactly will go in path and host   and origin
>2. how exactly to send the parameters  ?

Just provide the parameter strings with the call.  Lws sticks them in the upgrade header transparently and the server will either like it without comment or drop the connection because of its own policies.


>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org

More information about the Libwebsockets mailing list