Releases: Hakkadaikon/websocket
Releases · Hakkadaikon/websocket
v2.1.5: Change icon / Add test case
v2.1.4: Fix macos build
v2.1.3: Nix build support / Change icon
v2.1.2: Docker multi stage build support
v2.1.1: Fix docker build error
v2.1.0: Support musl build
🥳v2.1.0🥳
What's changed
- Support musl build
- Organize link flags (linux: -flto=auto -> -fno-lto)
Contributors
v2.0.1: Patch update (Fix README.md / int -> int32_t)
🥳v2.0.1🥳
What's changed
- Fix README.md (build)
- Change type to websocket.h (int -> int32_t)
Contributors
v2.0.0: GLIBC Independent
🥳v2.0.0🥳
What's changed
- GLIBC Independent
- Linux & x86_64 & debug build only
- Organize compile / link flags
- Add debug shells
Contributors
v1.0.0: First release
🥳 v1.0.0 🥳
What's changed
New release !
Support
- opcode
- 0x0 (continuation) : No
- 0x1 (text) : Yes (Interpret with user callbacks)
- 0x2 (binary) : Yes (Interpret with user callbacks)
- 0x8 (close) : Yes
- 0x9 (ping) : No
- 0xA (pong) : Yes (When a ping is received, a pong is sent back.)
- TLS Support : No
- Sub protocol : No (Sec-WebSocket-Protocol)
- Extensions : No (Sec-WebSocket-Extensions)
- Compression / Decode : No
Build
# release build
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
make BUILD=release -C examples/echoback
# debug build
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
make BUILD=debug -C examples/echoback Install
# default install dir:
# - /usr/local/lib/libwsserver.a
# - /usr/local/include/websocket.h
sudo cmake --install buildExample (echo back)
#include <stddef.h>
#include <websocket.h>
void websocket_receive_callback(
const int client_sock,
PWebSocketFrame frame,
const size_t buffer_capacity,
char* response_buffer)
{
switch (frame->opcode) {
case WEBSOCKET_OP_CODE_TEXT: {
frame->mask = 0;
size_t frame_size = create_websocket_frame(frame, buffer_capacity, response_buffer);
if (frame_size == 0) {
log_error("Failed to create websocket frame.\n");
return;
}
websocket_send(client_sock, frame_size, response_buffer);
} break;
default:
break;
}
}
void websocket_connect_callback(int client_sock)
{
printf("[user] connect. socket fd : %d\n", client_sock);
fflush(stdout);
}
void websocket_disconnect_callback(int client_sock)
{
printf("[user] disconnect. socket fd : %d\n", client_sock);
fflush(stdout);
}
int main()
{
WebSocketInitArgs init_args;
init_args.port_num = 8080;
init_args.backlog = 5;
int server_sock = websocket_server_init(&init_args);
if (server_sock < WEBSOCKET_ERRORCODE_NONE) {
log_error("websocket server init error.\n");
return 1;
}
WebSocketLoopArgs loop_args;
loop_args.server_sock = server_sock;
loop_args.callbacks.receive_callback = websocket_receive_callback;
loop_args.callbacks.connect_callback = websocket_connect_callback;
loop_args.callbacks.disconnect_callback = websocket_disconnect_callback;
loop_args.buffer_capacity = 1024;
websocket_server_loop(&loop_args);
websocket_close(server_sock);
log_error("websocket server end.\n");
return 0;
}