All Projects → rohanrhu → Cebsocket

rohanrhu / Cebsocket

Licence: mit
Lightweight WebSocket library for C.

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Cebsocket

Turbo Ws
💨 Blazing fast low-level WebSocket server
Stars: ✭ 647 (+786.3%)
Mutual labels:  websocket, websocket-server
Oatpp Websocket
oatpp-websocket submodule.
Stars: ✭ 26 (-64.38%)
Mutual labels:  websocket, websocket-server
Cowboy
Small, fast, modern HTTP server for Erlang/OTP.
Stars: ✭ 6,533 (+8849.32%)
Mutual labels:  websocket, websocket-server
Websocket
The Hoa\Websocket library.
Stars: ✭ 421 (+476.71%)
Mutual labels:  websocket, websocket-server
Babl
Low-latency WebSocket Server
Stars: ✭ 37 (-49.32%)
Mutual labels:  websocket, websocket-server
Cppserver
Ultra fast and low latency asynchronous socket server & client C++ library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and 10K connections problem solution
Stars: ✭ 528 (+623.29%)
Mutual labels:  websocket, websocket-server
Beetlex
high performance dotnet core socket tcp communication components, support TLS, HTTP, HTTPS, WebSocket, RPC, Redis protocols, custom protocols and 1M connections problem solution
Stars: ✭ 802 (+998.63%)
Mutual labels:  websocket, websocket-server
Websocketlistener
A lightweight and scalable asynchronous WebSocket listener
Stars: ✭ 295 (+304.11%)
Mutual labels:  websocket, websocket-server
Laravel Websockets Chat Example
Example of a real-time chat system built with the Laravel WebSockets package, VueJs, and Laravel-echo.
Stars: ✭ 65 (-10.96%)
Mutual labels:  websocket, websocket-server
Websock3ds
Example websocket server for Nintendo 3DS
Stars: ✭ 13 (-82.19%)
Mutual labels:  websocket, websocket-server
Microwebsrv
A micro HTTP Web server that supports WebSockets, html/python language templating and routing handlers, for MicroPython (used on Pycom modules & ESP32)
Stars: ✭ 420 (+475.34%)
Mutual labels:  websocket, websocket-server
Sockjs
SockJS server for rust language
Stars: ✭ 63 (-13.7%)
Mutual labels:  websocket, websocket-server
Websocket
simple php websocket server + demos + yii/yii2 integration + php 7 support
Stars: ✭ 363 (+397.26%)
Mutual labels:  websocket, websocket-server
Autobahn Testsuite
Autobahn WebSocket protocol testsuite
Stars: ✭ 603 (+726.03%)
Mutual labels:  websocket, websocket-server
Websockets
Library for building WebSocket servers and clients in Python
Stars: ✭ 3,724 (+5001.37%)
Mutual labels:  websocket, websocket-server
Netcoreserver
Ultra fast and low latency asynchronous socket server & client C# .NET Core library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and 10K connections problem solution
Stars: ✭ 799 (+994.52%)
Mutual labels:  websocket, websocket-server
Ws
Simple to use, blazing fast and thoroughly tested WebSocket client and server for Node.js
Stars: ✭ 17,419 (+23761.64%)
Mutual labels:  websocket, websocket-server
Microwebsrv2
The last Micro Web Server for IoTs (MicroPython) or large servers (CPython), that supports WebSockets, routes, template engine and with really optimized architecture (mem allocations, async I/Os). Ready for ESP32, STM32 on Pyboard, Pycom's chipsets (WiPy, LoPy, ...). Robust, efficient and documented!
Stars: ✭ 295 (+304.11%)
Mutual labels:  websocket, websocket-server
Awesome Websockets
A curated list of Websocket libraries and resources.
Stars: ✭ 850 (+1064.38%)
Mutual labels:  websocket, websocket-server
Jiny
Lightweight, modern, simple JVM web framework for rapid development in the API era
Stars: ✭ 40 (-45.21%)
Mutual labels:  websocket, websocket-server

cebsocket: a lightweight websocket library for C

Cebsocket is a lightweight websocket library for C.

Usage

Usage is easy and simple. You can look to examples/ directory. You can build examples with make command.

Simple WebSocket Server

Here is an example for creating simple WebSocket server.

void on_data(cebsocket_clients_t* client, char* data) {
    printf("WebSocket Message: %s\n", data);
    
    cebsocket_send(client, "Hello from WebSocket server!");
}

void on_connected(cebsocket_clients_t* client) {
    printf("Client connected #%d\n", client->id);
}

void on_disconnected(cebsocket_clients_t* client) {
    printf("Client disconnected #%d\n", client->id);
}

int main() {
    printf("Starting WebSocket server..\n");

    cebsocket_t* ws = cebsocket_init(8080);
    
    ws->on_data = on_data;
    ws->on_connected = on_connected;
    ws->on_disconnected = on_disconnected;
    
    cebsocket_listen(ws);
    
    return 0;
}

What about HTTP?

Cebsocket is designed to only handle WebSocket requests as a HTTP server. You can use it with Apache's mod_proxy_ws_tunnel.

What about SSL?

Also you can use Apache's mod_proxy_ws_tunnel for SSL.

Build

Building is simple just do make.

make clean; make

You will see websocket.o. You can use it like:

gcc -o hello hello.c websocket.o
./hello

Events

Thread Safety

Event handler functions get called from client thread so you must be sure for they are thread-safe.

void on_connected(cebsocket_clients_t* client)

Called when a client connected.

void on_disconnected(cebsocket_clients_t* client)

Called when a client disconnected.

void on_message(cebsocket_clients_t* client, char* data)

Called when a message is arrived from client.

Functions

extern cebsocket_t* cebsocket_init(int port)

Creates WebSocket server instance.

extern void cebsocket_listen(cebsocket_t* ws)

Starts listening new connections.

extern void cebsocket_send(cebsocket_clients_t* client, char* message)

Sends message to client.

Types

cebsocket_t

The WebSocket server instance.

typedef struct cebsocket {
    int port;
    char* host_address;
    char* bind_address;
    cebsocket_clients_t* clients;
    void (*on_data)(cebsocket_clients_t*, char*);
    void (*on_connected)(cebsocket_clients_t*);
    void (*on_disconnected)(cebsocket_clients_t*);
} cebsocket_t;

cebsocket_clients_t

The WebSocket client instance. It is also a linked-list.

typedef struct cebsocket_clients {
    cebsocket_t* ws;
    int id;
    int socket;
    int server_socket;
    int address;
    char* ws_key;
    void* data;
    cebsocket_clients_t* prev;
    cebsocket_clients_t* next;
} cebsoket_clients_t;

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].