Skip to content

Releases: Hakkadaikon/websocket

v2.1.5: Change icon / Add test case

16 Sep 19:36

Choose a tag to compare

🥳v2.1.5🥳

What's changed

  • Change icon
  • Add test case

Contributors

v2.1.4: Fix macos build

11 Mar 15:03
8fd398c

Choose a tag to compare

🥳v2.1.4🥳

What's changed

  • Fix macos build

Contributors

v2.1.3: Nix build support / Change icon

25 Feb 19:11
0d7437f

Choose a tag to compare

🥳v2.1.3🥳

What's changed

  • Nix build support
  • Change icon

Contributors

v2.1.2: Docker multi stage build support

20 Feb 15:27

Choose a tag to compare

🥳v2.1.2🥳

What's changed

  • Docker multi stage build support

Contributors

v2.1.1: Fix docker build error

20 Feb 10:28

Choose a tag to compare

⚠️ v2.1.1 ⚠️

What's changed

  • Fix docker build error

Contributors

v2.1.0: Support musl build

20 Feb 07:26

Choose a tag to compare

🥳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)

20 Feb 00:35
8ea56f9

Choose a tag to compare

🥳v2.0.1🥳

What's changed

  • Fix README.md (build)
  • Change type to websocket.h (int -> int32_t)

Contributors

v2.0.0: GLIBC Independent

19 Feb 11:06
8ea56f9

Choose a tag to compare

🥳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

08 Feb 15:05

Choose a tag to compare

🥳 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 build

Example (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;
}

Contributors