-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathwebsocket.c
More file actions
27 lines (23 loc) · 719 Bytes
/
websocket.c
File metadata and controls
27 lines (23 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdio.h>
#include <string.h>
#include <cweb.h>
static void on_open(struct cweb_context *ctx, websocket_t *ws) {
printf("WebSocket opened\n");
}
static void on_message(struct cweb_context *ctx, websocket_t *ws, const char *message, size_t length) {
char response[1024];
snprintf(response, sizeof(response), "You: %s", message);
ws->send(ws, response, strlen(response));
}
static void on_close(struct cweb_context *ctx, websocket_t *ws) {
printf("WebSocket closed\n");
}
/* Define the routes for the module */
export module_t config = {
.name = "websocket",
.author = "cweb",
.websockets = {
{"/websocket", on_open, on_message, on_close},
},
.ws_size = 1,
};