libwebsockets
Lightweight C library for HTML5 websockets
Client related functions

Data Structures

struct  lws_client_connect_info
 

Enumerations

enum  lws_client_connect_ssl_connection_flags {
  LCCSCF_USE_SSL = (1 << 0), LCCSCF_ALLOW_SELFSIGNED = (1 << 1), LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK = (1 << 2), LCCSCF_ALLOW_EXPIRED = (1 << 3),
  LCCSCF_PIPELINE = (1 << 16)
}
 

Functions

LWS_VISIBLE LWS_EXTERN struct lws * lws_client_connect_via_info (const struct lws_client_connect_info *ccinfo)
 
LWS_VISIBLE LWS_EXTERN int lws_init_vhost_client_ssl (const struct lws_context_creation_info *info, struct lws_vhost *vhost)
 
LWS_VISIBLE LWS_EXTERN int lws_http_client_read (struct lws *wsi, char **buf, int *len)
 
LWS_VISIBLE LWS_EXTERN unsigned int lws_http_client_http_response (struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN void lws_client_http_body_pending (struct lws *wsi, int something_left_to_send)
 

Detailed Description

Client releated functions

Enumeration Type Documentation

◆ lws_client_connect_ssl_connection_flags

#include <include/libwebsockets/lws-client.h>

enum lws_client_connect_ssl_connection_flags - flags that may be used with struct lws_client_connect_info ssl_connection member to control if and how SSL checks apply to the client connection being created

Enumerator
LCCSCF_PIPELINE 

Serialize / pipeline multiple client connections on a single connection where possible.

HTTP/1.0: possible if Keep-Alive: yes sent by server HTTP/1.1: always possible... uses pipelining HTTP/2: always possible... uses parallel streams

36  {
37  LCCSCF_USE_SSL = (1 << 0),
38  LCCSCF_ALLOW_SELFSIGNED = (1 << 1),
39  LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK = (1 << 2),
40  LCCSCF_ALLOW_EXPIRED = (1 << 3),
41 
42  LCCSCF_PIPELINE = (1 << 16),
50 };
Definition: lws-client.h:42

Function Documentation

◆ lws_client_connect_via_info()

LWS_VISIBLE LWS_EXTERN struct lws* lws_client_connect_via_info ( const struct lws_client_connect_info ccinfo)

#include <include/libwebsockets/lws-client.h>

lws_client_connect_via_info() - Connect to another websocket server

Parameters
ccinfopointer to lws_client_connect_info struct
 This function creates a connection to a remote server using the
 information provided in ccinfo.

◆ lws_http_client_http_response()

LWS_VISIBLE LWS_EXTERN unsigned int lws_http_client_http_response ( struct lws *  wsi)

#include <include/libwebsockets/lws-client.h>

lws_http_client_http_response() - get last HTTP response code

Parameters
wsiclient connection

Returns the last server response code, eg, 200 for client http connections.

You should capture this during the LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP callback, because after that the memory reserved for storing the related headers is freed and this value is lost.

◆ lws_http_client_read()

LWS_VISIBLE LWS_EXTERN int lws_http_client_read ( struct lws *  wsi,
char **  buf,
int *  len 
)

#include <include/libwebsockets/lws-client.h>

lws_http_client_read() - consume waiting received http client data

Parameters
wsiclient connection
bufpointer to buffer pointer - fill with pointer to your buffer
lenpointer to chunk length - fill with max length of buffer

This is called when the user code is notified client http data has arrived. The user code may choose to delay calling it to consume the data, for example waiting until an onward connection is writeable.

For non-chunked connections, up to len bytes of buf are filled with the received content. len is set to the actual amount filled before return.

For chunked connections, the linear buffer content contains the chunking headers and it cannot be passed in one lump. Instead, this function will call back LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ with in pointing to the chunk start and len set to the chunk length. There will be as many calls as there are chunks or partial chunks in the buffer.

◆ lws_init_vhost_client_ssl()

LWS_VISIBLE LWS_EXTERN int lws_init_vhost_client_ssl ( const struct lws_context_creation_info info,
struct lws_vhost *  vhost 
)

#include <include/libwebsockets/lws-client.h>

lws_init_vhost_client_ssl() - also enable client SSL on an existing vhost

Parameters
infoclient ssl related info
vhostwhich vhost to initialize client ssl operations on

You only need to call this if you plan on using SSL client connections on the vhost. For non-SSL client connections, it's not necessary to call this.

The following members of info are used during the call

  - options must have LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT set,
      otherwise the call does nothing
  - provided_client_ssl_ctx must be NULL to get a generated client
      ssl context, otherwise you can pass a prepared one in by setting it
  - ssl_cipher_list may be NULL or set to the client valid cipher list
  - ssl_ca_filepath may be NULL or client cert filepath
  - ssl_cert_filepath may be NULL or client cert filepath
  - ssl_private_key_filepath may be NULL or client cert private key

You must create your vhost explicitly if you want to use this, so you have a pointer to the vhost. Create the context first with the option flag LWS_SERVER_OPTION_EXPLICIT_VHOSTS and then call lws_create_vhost() with the same info struct.