|
Robotran C Documentation
|
Go to the documentation of this file.
54 #define MESSAGE_LENGTH 2048
58 #define MAX_FRAME_LENGTH (16*1024*1024)
70 #define WS_KEYMS_LEN (WS_KEY_LEN + WS_MS_LEN)
74 #define MAGIC_STRING "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
84 #define WS_HS_REQ "Sec-WebSocket-Key"
89 #define WS_HS_ACCLEN 130
94 #define WS_HS_ACCEPT \
95 "HTTP/1.1 101 Switching Protocols\r\n" \
96 "Upgrade: websocket\r\n" \
97 "Connection: Upgrade\r\n" \
98 "Sec-WebSocket-Accept: "
113 #define WS_FIN_SHIFT 7
118 #define WS_FR_OP_CONT 0
123 #define WS_FR_OP_TXT 1
128 #define WS_FR_OP_BIN 2
133 #define WS_FR_OP_CLSE 8
138 #define WS_FR_OP_PING 0x9
143 #define WS_FR_OP_PONG 0xA
148 #define WS_FR_OP_UNSUPPORTED 0xF
158 #define WS_CLSE_NORMAL 1000
162 #define WS_CLSE_PROTERR 1002
167 #define WS_CLSE_INVUTF8 1007
176 #define WS_STATE_CONNECTING 0
180 #define WS_STATE_OPEN 1
184 #define WS_STATE_CLOSING 2
188 #define WS_STATE_CLOSED 3
198 #define MS_TO_NS(x) ((x)*1000000)
202 #define TIMEOUT_MS (500)
213 #define DEBUG(...) fprintf(stderr, __VA_ARGS__)
220 #define SEND(client,buf,len) send_all((client), (buf), (len), MSG_NOSIGNAL)
221 #define RECV(fd,buf,len) recv((fd)->client_sock, (buf), (len), 0)
223 #define SEND(client,buf,len) write(fileno(stdout), (buf), (len))
224 #define RECV(fd,buf,len) read((fd)->client_sock, (buf), (len))
267 const unsigned char *msg, uint64_t msg_size,
int type);
313 ws_cli_conn_t *cli,
const char *msg, uint64_t size,
int type);
315 uint16_t port,
const char *msg, uint64_t size,
int type);
327 extern void ws_ping(ws_cli_conn_t *cli,
int threshold);
330 extern int ws_file(
struct ws_events *evs,
const char *file);
int ws_sendframe_bcast(uint16_t port, const char *msg, uint64_t size, int type)
Send an WebSocket frame with some payload data to all clients connected into the same port.
Definition: ws.c:682
void ws_set_connection_context(ws_cli_conn_t *cli, void *ptr)
Set connection context.
Definition: ws.c:112
int ws_socket(struct ws_server *ws_srv)
Main loop for the server.
Definition: ws.c:1940
int get_handshake_response(char *hsrequest, char **hsresponse)
Gets the complete response to accomplish a succesfully handshake.
Definition: handshake.c:87
void(* onmessage)(ws_cli_conn_t *client, const unsigned char *msg, uint64_t msg_size, int type)
On message event, called when a client sends a text or binary message.
Definition: ws.h:266
static ws_cli_conn_t * client
Definition: visu_websocket.cc:49
int ws_sendframe_txt_bcast(uint16_t port, const char *msg)
Sends a broadcast WebSocket text frame.
Definition: ws.c:828
void * ws_get_connection_context(ws_cli_conn_t *cli)
Get connection context.
Definition: ws.c:120
int thread_loop
Whether if the ws_socket() should create a new thread and be non-blocking (1) or not (0).
Definition: ws.h:287
int ws_close_client(ws_cli_conn_t *cli)
Close the client connection for the given client with normal close code (1000) and no reason string.
Definition: ws.c:893
int ws_sendframe(ws_cli_conn_t *cli, const char *msg, uint64_t size, int type)
Send an WebSocket frame with some payload data.
Definition: ws.c:663
uint16_t port
Listening port.
Definition: ws.h:282
void * context
Server context.
Definition: ws.h:300
int ws_get_state(ws_cli_conn_t *cli)
For a given client, gets the current state for the connection, or -1 if invalid.
Definition: ws.c:875
Client socks.
Definition: ws.c:70
void ws_ping(ws_cli_conn_t *cli, int threshold)
Sends a PING frame to the client cli with threshold threshold.
Definition: ws.c:783
void(* onclose)(ws_cli_conn_t *client)
On close event, called when a client disconnects.
Definition: ws.h:261
struct ws_events evs
Server events.
Definition: ws.h:295
char * ws_getport(ws_cli_conn_t *client)
Gets the IP port relative to a client connection opened by the server.
Definition: ws.c:493
uint32_t timeout_ms
Ping timeout in milliseconds.
Definition: ws.h:291
void(* onopen)(ws_cli_conn_t *client)
On open event, called when a new client connects.
Definition: ws.h:257
int get_handshake_accept(char *wsKey, unsigned char **dest)
Gets the field Sec-WebSocket-Accept on response, by an previously informed key.
Definition: handshake.c:47
events Web Socket events types.
Definition: ws.h:252
void * ws_get_server_context(ws_cli_conn_t *cli)
Get server context.
Definition: ws.c:104
int ws_sendframe_bin(ws_cli_conn_t *cli, const char *msg, uint64_t size)
Sends a WebSocket binary frame.
Definition: ws.c:842
int ws_sendframe_txt(ws_cli_conn_t *cli, const char *msg)
Sends a WebSocket text frame.
Definition: ws.c:815
int ws_sendframe_bin_bcast(uint16_t port, const char *msg, uint64_t size)
Sends a broadcast WebSocket binary frame.
Definition: ws.c:856
char * ws_getaddress(ws_cli_conn_t *client)
Gets the IP address relative to a client connection opened by the server.
Definition: ws.c:475
server Web Socket server parameters
Definition: ws.h:273
const char * host
Required hostname that the wsServer will bind to.
Definition: ws.h:278