rabbitmq-c  0.5.3
C AMQP Client library for RabbitMQ
Data Structures | Typedefs | Functions
websocket.h File Reference

Go to the source code of this file.

Data Structures

struct  websocket_message_event_t
 websocket_message_event_t struct. More...

Typedefs

typedef struct websocket_t_stct websocket_t
 websocket_t is a struct refer to WebSocket object.

Functions

websocket_twebsocket_new ()
 websocket_new Creates a websocket_t object.
void websocket_free (websocket_t *ws)
 websocket_free Frees websocket_t object from memory.
int websocket_connect (websocket_t *ws, const char *location, const char *protocol, const char *extension)
 websocket_connect Connections with the server.
int websocket_send_text (websocket_t *ws, const char *text)
 websocket_send_text Sends a NULL terminated string to server.
int websocket_send_binary (websocket_t *ws, const char *binary, size_t size)
 websocket_send_binary Sends a binary block data to server.
int websocket_send_binaryv (websocket_t *ws, const struct iovec *iov, int iovcnt)
 websocket_send_binaryv Sends multiple binary blocks data to server.
int websocket_close (websocket_t *ws)
 websocket_close Disconnects with the server.
int websocket_close_with_reason (websocket_t *ws, int code, const char *reason)
 websocket_close Disconnects with the server with code and reason.
websocket_message_event_twebsocket_recv (websocket_t *ws)
 websocket_recv Receive data from the WebSocket connection.
const char * websocket_url (websocket_t *ws)
 websocket_url Gets the url of the connection.
int websocket_readystate (websocket_t *ws)
 websocket_readystate returns the readstate of the WebSocket connection.
const char * websocket_protocol (websocket_t *ws)
 websocket_protocol Gets names of all the enabled protocols that have been successfully negotiated between the client and the server during the initial handshake.
const char * websocket_extension (websocket_t *ws)
 websocket_extension Gets names of all the enabled extensions that have been successfully negotiated between the client and the server during the initial handshake.
int websocket_ssl_set_cacert (websocket_t *ws, const char *cacert)
 websocket_ssl_set_cacert Sets the ca certificate store for SSL WebSocket connection.
int websocket_ssl_set_clientkey (websocket_t *ws, const char *cert, const char *key)
 websocket_ssl_set_cacert Sets the client certificates and client key file for SSL WebSocket connection.
int websocket_ssl_set_verify_callback (websocket_t *ws, int(*callback)(int preverify_ok, X509_STORE_CTX *ctx))
 websocket_ssl_set_verify_callback Sets the client verify callback function for SSL WebSocket connection.

Detailed Description


Typedef Documentation

typedef struct websocket_t_stct websocket_t

websocket_t is a struct refer to WebSocket object.

WebSocket provides bi-directional communications for text and binary messaging via the Kaazing Gateway. Refer to http://www.w3.org/TR/websockets/ for the published standard W3C WebSocket API specification.


Function Documentation

websocket_close Disconnects with the server.

Parameters:
wspointer of websocket_t object
Returns:
int. 0 - successful, 1 - failed
int websocket_close_with_reason ( websocket_t ws,
int  code,
const char *  reason 
)

websocket_close Disconnects with the server with code and reason.

based on RFc-6455, WebSocket client can disconnect with its own data.

Parameters:
wspointer of websocket_t object
codeint close code that is sent to server. the code must equal to 1000 or in range 3000 to 4999
reasonpointer of null terminated string that is sent to server, the reason length must be less than 127
Returns:
int. 0 - successful, 1 - failed
int websocket_connect ( websocket_t ws,
const char *  location,
const char *  protocol,
const char *  extension 
)

websocket_connect Connections with the server.

Clients should call send/receive data when the connection has been established.

Parameters:
wspointer of websocket_t object
locationpointer of null terminated string that contains url of server, for example "ws://echo.websocket.org"
protocolpointer of null terminated string that contains client's protocol(s). NULL for no protocol. use comma separated format for multiple protocols. for example "protcol1,protocol2"
extensionpointer of null terminated string that contains client's extension(s). NULL for no protocol. use comma separated format for multiple protocols. for example "extension1 param1=10;param2=test,extension2"
Returns:
int. 0 - successful, 1 - failed
const char* websocket_extension ( websocket_t ws)

websocket_extension Gets names of all the enabled extensions that have been successfully negotiated between the client and the server during the initial handshake.

Parameters:
wspointer of websocket_t object
Returns:
pointer of null terminated string that contains the extension(s). comma separated for multiple extensions
void websocket_free ( websocket_t ws)

websocket_free Frees websocket_t object from memory.

Clients should always use websocket_free to deallocate websocket_t object instead of call free() directly.

Parameters:
pointerof websocket_t object

websocket_new Creates a websocket_t object.

Clients should always use websocket_new to create websocket_t object instead of malloc directly.

Returns:
websocket_t object
const char* websocket_protocol ( websocket_t ws)

websocket_protocol Gets names of all the enabled protocols that have been successfully negotiated between the client and the server during the initial handshake.

Parameters:
wspointer of websocket_t object
Returns:
pointer of null terminated string that contains the protocol(s). comma separated for multiple protocols

websocket_readystate returns the readstate of the WebSocket connection.

Parameters:
wspointer of websocket_t object
Returns:
int the readystate of the WebSocket connection. 0 - connecting, 1 - open, 2 - closing, 3 - closed

websocket_recv Receive data from the WebSocket connection.

Client calls websocket_recv to retrieve data that was sent from server. This function is a block call. It returns when there is data available on the WebSocket connection. If the connection is disconnected, then a message event with type equals to CLOSED will be returned. After CLOSED event, call websocket_recv will return NULL.

Parameters:
wspointer of websocket_t object
codeint close code that is sent to server. the code must equal to 1000 or in range 3000 to 4999
rasonpointer of null terminated string that is sent to server, the reason length must be less than 127
Returns:
int. 0 - successful, 1 - failed
int websocket_send_binary ( websocket_t ws,
const char *  binary,
size_t  size 
)

websocket_send_binary Sends a binary block data to server.

Parameters:
wspointer of websocket_t object
binarypointer of binary block that is sent to server.
intsize length of binary block that is sent to server.
Returns:
int. 0 - successful, 1 - failed
int websocket_send_binaryv ( websocket_t ws,
const struct iovec *  iov,
int  iovcnt 
)

websocket_send_binaryv Sends multiple binary blocks data to server.

Parameters:
wspointer of websocket_t object
iovpointer of struct iovec that is sent to server. please refer to sys/uio.h for details about iovec
intiovcnt size of iovec array that is sent to server.
Returns:
int. 0 - successful, 1 - failed
int websocket_send_text ( websocket_t ws,
const char *  text 
)

websocket_send_text Sends a NULL terminated string to server.

Parameters:
wspointer of websocket_t object
textpointer of null terminated string that is sent to server, for example "hello websocket"
Returns:
int. 0 - successful, 1 - failed
int websocket_ssl_set_cacert ( websocket_t ws,
const char *  cacert 
)

websocket_ssl_set_cacert Sets the ca certificate store for SSL WebSocket connection.

this function sets the client ca certificate store. refer to openssl document for details. Client should call this function before calling websocket_connect()

Parameters:
wspointer of websocket_t object
cacertpoint to the ca cert file location
Returns:
int 0 - success, 1 - failed
int websocket_ssl_set_clientkey ( websocket_t ws,
const char *  cert,
const char *  key 
)

websocket_ssl_set_cacert Sets the client certificates and client key file for SSL WebSocket connection.

This function sets the client certificate file and key file. refer to openssl document for details. Client should call this function before calling websocket_connect()

Parameters:
wspointer of websocket_t object
certpoint to the client cert file location
keypoint to the client key file location
Returns:
int 0 - success, 1 - failed
int websocket_ssl_set_verify_callback ( websocket_t ws,
int(*)(int preverify_ok, X509_STORE_CTX *ctx)  callback 
)

websocket_ssl_set_verify_callback Sets the client verify callback function for SSL WebSocket connection.

This function sets the client verify callback function . refer to openssl document for details. Client should call this function before calling websocket_connect()

Parameters:
wspointer of websocket_t object
callbackpoint to client verify callback function
Returns:
int 0 - success, 1 - failed
const char* websocket_url ( websocket_t ws)

websocket_url Gets the url of the connection.

this function returns the final url of the WebSocket. note: when client connect to kaazing gateway with balancer service. the final url may be different from the original url that client used when connect.

Parameters:
wspointer of websocket_t object
Returns:
pointer of null terminated string that contains the final url
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines