All Projects → cjhdev → wic

cjhdev / wic

Licence: other
WebSockets in C for Embedded Applications

Programming Languages

c
50402 projects - #5 most used programming language
C++
36643 projects - #6 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to wic

Singularity
Singularity: Application containers for Linux
Stars: ✭ 2,290 (+3716.67%)
Mutual labels:  portable
Messenger For Desktop
This is not an official Facebook product, and is not affiliated with, or sponsored or endorsed by, Facebook.
Stars: ✭ 2,180 (+3533.33%)
Mutual labels:  portable
Postgresql Portable
Portable version of the PostgreSQL Database Server, for Windows
Stars: ✭ 237 (+295%)
Mutual labels:  portable
Usb Disk Ejector
A program that allows you to quickly remove drives in Windows. It can eject USB disks, Firewire disks and memory cards. It is a quick, flexible, portable alternative to using Windows' "Safely Remove Hardware" dialog.
Stars: ✭ 175 (+191.67%)
Mutual labels:  portable
Atom Portable
Portable version of the Atom text editor
Stars: ✭ 187 (+211.67%)
Mutual labels:  portable
Libagar
Cross-Platform GUI Toolkit (stable)
Stars: ✭ 212 (+253.33%)
Mutual labels:  portable
Facenet mtcnn to mobile
convert facenet and mtcnn models from tensorflow to tensorflow lite and coreml (使用 TFLite 将 FaceNet 和 MTCNN 移植到移动端)
Stars: ✭ 166 (+176.67%)
Mutual labels:  portable
osmid
osmid is a tool to bridge MIDI and OSC. It is currently in use in Sonic Pi
Stars: ✭ 63 (+5%)
Mutual labels:  portable
Wagon
免安裝可攜的 Laravel 開發環境
Stars: ✭ 189 (+215%)
Mutual labels:  portable
Mlibc
Portable C standard library
Stars: ✭ 225 (+275%)
Mutual labels:  portable
Baulk
baulk - Minimal Package Manager for Windows
Stars: ✭ 177 (+195%)
Mutual labels:  portable
Fast Ide
🕺Fast Integrated Development Environment 😻
Stars: ✭ 181 (+201.67%)
Mutual labels:  portable
Sftpgo
Fully featured and highly configurable SFTP server with optional HTTP, FTP/S and WebDAV support - S3, Google Cloud Storage, Azure Blob
Stars: ✭ 3,534 (+5790%)
Mutual labels:  portable
Doomsday Engine
A portable, enhanced source port of Doom, Heretic and Hexen.
Stars: ✭ 175 (+191.67%)
Mutual labels:  portable
Boost.simd
Boost SIMD
Stars: ✭ 238 (+296.67%)
Mutual labels:  portable
Div Games Studio
Complete cross platform games development package, originally for DOS but now available on modern platforms.
Stars: ✭ 168 (+180%)
Mutual labels:  portable
Pockint
A portable OSINT Swiss Army Knife for DFIR/OSINT professionals 🕵️ 🕵️ 🕵️
Stars: ✭ 196 (+226.67%)
Mutual labels:  portable
tgc
A Tiny, portable, precise, incremental mark-sweep GC designed for C++.
Stars: ✭ 36 (-40%)
Mutual labels:  portable
Mipp
MIPP is a portable wrapper for SIMD instructions written in C++11. It supports NEON, SSE, AVX and AVX-512.
Stars: ✭ 253 (+321.67%)
Mutual labels:  portable
Libonnx
A lightweight, portable pure C99 onnx inference engine for embedded devices with hardware acceleration support.
Stars: ✭ 217 (+261.67%)
Mutual labels:  portable

WebSockets in C

WIC is a C99 implementation of rfc6455 websockets designed for embedded applications.

WIC decouples the websocket protocol from the transport layer. This makes it possible to use WIC over any transport layer assuming that you are prepared to do the integration work.

WIC is a work in progress. This means that:

  • server role is not supported yet
  • handshake implementation is not very robust
  • interfaces may change

Features

  • doesn't call malloc
  • handshake header fields passed through to application
  • convenience functions for dissecting URLs
  • convenience functions for implementing redirection
  • works with any transport layer you like
  • automatic payload fragmentation on receive
  • trivial to integrate with an existing build system

Limitations

  • interfaces are not thread-safe (provide your own solution)
  • handshake headers are only accessible at the moment a websocket becomes connected (i.e. wic_get_state() == WIC_STATE_READY)
  • doesn't support extensions
  • there are a bewildering number of function pointers

The handshake field limitation is a consequence of storing header fields in the same buffer as used for receiving websocket frames. Applications that require header fields to persist beyond WIC_STATE_READY will need to copy the fields when they are available.

Integrations

Compiling

  • add include to the search path
  • compile sources in src

There are some macros you can define. These listed at the top of include/wic.h and in the API documentation.

The WIC_PORT_HEADER macro can be used to define a filename which will be included into wic.h. This might be the most convenient place to define/redefine other macros.

Usage

Below is an example of a client that:

  • connects
  • sends a "hello world" text
  • closes normally
#include "wic.h"

int main(int argc, char **argv)
{
    int s;
    static uint8_t rx[1000];
    struct wic_inst inst;
    struct wic_init_arg arg = {0};

    arg.rx = rx; arg.rx_max = sizeof(rx);    

    arg.on_send = on_send_handler;    
    arg.on_open = on_open_handler;        
    arg.on_message = on_message_handler;        
    arg.on_close_transport = on_close_transport_handler;        
    arg.on_buffer = on_buffer_handler;        

    arg.app = &s;
    arg.url = "ws://echo.websocket.org/";
    arg.role = WIC_ROLE_CLIENT;

    if(!wic_init(&inst, &arg)){

        exit(EXIT_FAILURE);
    };

    if(transport_open_client(wic_get_url_schema(&inst),
            wic_get_url_hostname(&inst), wic_get_url_port(&inst), &s)){

        if(wic_start(&inst) == WIC_STATUS_SUCCESS){

            while(transport_recv(s, &inst));
        }
        else{

            transport_close(&s);
        }
    }
    
    exit(EXIT_SUCCESS);
}

static void on_open_handler(struct wic_inst *inst)
{
    const char msg[] = "hello world";

    wic_send_text(inst, true, msg, strlen(msg));    
} 

static void on_close_transport_handler(struct wic_inst *inst)
{
    transport_close((int *)wic_get_app(inst));
}

static void on_send_handler(struct wic_inst *inst, const void *data,
        size_t size, enum wic_frame_type type)
{
    transport_write(*(int *)wic_get_app(inst), data, size);
}

static void *on_buffer_handler(struct wic_inst *inst, size_t min_size,
        enum wic_frame_type type, size_t *max_size)
{
    static uint8_t tx[1000U];

    *max_size = sizeof(tx);

    return (min_size <= sizeof(tx)) ? tx : NULL;
}

static bool on_message_handler(struct wic_inst *inst, enum wic_encoding encoding, bool fin, const char *data, uint16_t size)
{
    if(encoding == WIC_ENCODING_UTF8){

        printf("received text: %.*s\n", size, data);
    }

    wic_close(inst);

    return true;
}

Acknowledgements

WIC integrates code from the following projects:

  • Joyent/Node-JS http-parser
  • Bjoern Hoehrmann's UTF8 parser
  • MBED TLS SHA1 (modified to suit this project)

The Autobahn Test Suite has been used for verification.

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].