An easy to use and powerful open source websocket library written in C.



Easy to use C library for websockets

This library allows for quick and easy development of applications that use the websocket protocol, without the need to focus on websocket protocol specifics nor even socket specifics. It handles the sockets and the protocol for you, allowing you to focus on the core logic of your application.

For those who wish to use their own sockets, the library is capable of being bound to existing fd's, allowing you to create your own socket logic and simply trigger libwebsock events on them. Support for tying your own libevent bases in to libwebsocket is also being worked on.

Currently, libwebsocket has the following features:

  • Event Callback Based
  • Support for SSL
  • Uses [libevent][2] for maximum portability (tested on Linux, FreeBSD and Mac OS)
  • Supports IPv4 and IPv6
  • Passes the Autobahn Test suite
  • Can handle the entire socket connection for you
  • Can be bound to existing file descriptors allowing you to use your own socket code

At the moment, it only supports sending unfragmented text frames using the default libwebsock_send_text() function. It is currently hardcoded to always send the FIN bit. Support is being integrated to allow fragmented messages to be sent, as detailed below.

Coming Soon:

  • Ability to tie in to existing libevent bases
  • Streaming functionality (for video, audio and file transfers)

This is a continuation of Payden Kyle Sutherlands original libwebsocket implementation.

Payden Sutherland passed away on September 24, 2014, mid-development of this library. The library is almost complete, and incredibly powerful - not to mention easy to use. I felt that picking it up and getting it finished was the right thing to do. All initial credit belongs to him for his hard work and time put in to the project.

  • License question

    License question


    I would like know, is this library under the GPL license or LGPL license? Because there's 2 license files in the project..

    Thank you.

    Kind regards, Sungtae

    opened by pchero 2
  • Random bug fixes

    Random bug fixes

    Just found out when going to open an issue on the original libwebsock repository that the author's dead. Since it seems like you're taking over... here's a few fixes.

    opened by shawnw 1
  • Potential for memory-based denial of service in winsock.c

    Potential for memory-based denial of service in winsock.c

            frame->state = sw_loaded_mask;
            frame->size = frame->payload_offset + frame->payload_len;
            if (frame->size > frame->rawdata_sz) {
                new_size = frame->size;
                new_size |= new_size >> 1;
                new_size |= new_size >> 2;
                new_size |= new_size >> 4;
                new_size |= new_size >> 8;
                new_size |= new_size >> 16;
                frame->rawdata_sz = new_size;
                frame->rawdata = (char *) lws_realloc(frame->rawdata, new_size);

    This portion of code would allow an attacker to set the packet header size far above the actual size of data being sent to the server, and the server would then allocate new memory based off of that information.

    If the purported payload length is different than the raw length, I suggest structuring the code around the assumption that the raw length is correct.

    opened by thereals0beit 1
  • Memory Leaks

    Memory Leaks

    libwebsock is failing the valgrind leak checks. I'm seeing it leak roughly 80kb per a connection. Obviously some allocated memory is not being freed up appropriately at the time of connect and disconnect. Need to dig through, find all the memory leaks and straighten them out.

    opened by JonnyWhatshisface 0
  • Compile Issues

    Compile Issues

    It's already known that there are a few compile issues. The workaround is in the docs/INSTALL.txt file. I'll be working on them to try and straighten it out once I correct the memory leaks and add a little additional functionality. Right now, it's not stable for production use.

    opened by JonnyWhatshisface 0
  • Crash on secure connect

    Crash on secure connect

    Before i figured out that there is a newer libwebsocket2 ;-) i ran into a crash immediately after establishment of a secure connection. It occured every time i connected with chrome or firefox. After some hours i figured out, that in the mentioned line the increment won't work in case the previous loop ran into the lws_free(current) command. So i changed it into the following and it works fine.

    while (tinfo != NULL) 
        if (pthread_equal(current_thread, wrapper->thread)) {
            // increment to next before free!!!
            tinfo = tinfo->next;
        } else {
            tinfo = tinfo->next;

    Maybe this info could save someone the day. Next of course i'll have a look on libwebsocket2.

    opened by hoegsi 0
  • Windows


    Hello, I plan to compile and use this project under Windows, are there any know issues or library uncompatibilities? (So far I'm testing in Linux so I would like to prevent issues when I migrate and compile in Windows).

    Thank you.

    opened by nzurita 0
  • Config instructions don't work on macOS

    Config instructions don't work on macOS

    Building on macOS requires a number of extra steps that aren't documented.

    1. Use Homebrew to install autoconf, glibtool, openssl, libevent.
    2. Edit and change libtoolize to glibtoolize. (Necessary because the OS already includes a different tool called libtool, so when Homebrew installs GNU libtool it prefixes its commands with a g to avoid mixups.)
    3. Now you can run
    4. Some more compiler flags need to be specified when configuring and building, so the compiler and linker can find the packages installed by Homebrew. Use CFLAGS="-I/usr/local/include -L/usr/local/lib -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib -lpthread -levent" ./configure && make

    After this is done, if you need to rebuild you should just be able to run make.

    opened by snej 2
  • libwebsock ./configure fails

    libwebsock ./configure fails

    Hi JonnyWhatshisface, I would like to use libwebsock for my C program. Cloning the git and running autogen worked just fine. However when I try CFLAGS="-lpthread -levent" ./configure following error lands in my config.log:

    This file contains any messages produced by compilers while
    running configure, to aid debugging if configure makes a mistake.
    It was created by libwebsock configure 1.0.7, which was
    generated by GNU Autoconf 2.69.  Invocation command line was
      $ ./configure 
    ## --------- ##
    ## Platform. ##
    ## --------- ##
    hostname = COMPUTESTICK
    uname -m = x86_64
    uname -r = 4.4.0-21-linuxium
    uname -s = Linux
    uname -v = #37+ics SMP Mon Apr 25 19:39:09 AEST 2016
    /usr/bin/uname -p = unknown
    /bin/uname -X     = unknown
    /bin/arch              = unknown
    /usr/bin/arch -k       = unknown
    /usr/convex/getsysinfo = unknown
    /usr/bin/hostinfo      = unknown
    /bin/machine           = unknown
    /usr/bin/oslevel       = unknown
    /bin/universe          = unknown
    PATH: /usr/local/sbin
    PATH: /usr/local/bin
    PATH: /usr/sbin
    PATH: /usr/bin
    PATH: /sbin
    PATH: /bin
    PATH: /usr/games
    PATH: /usr/local/games
    ## ----------- ##
    ## Core tests. ##
    ## ----------- ##
    configure:2328: checking for a BSD-compatible install
    configure:2396: result: /usr/bin/install -c
    configure:2407: checking whether build environment is sane
    configure:2462: result: yes
    configure:2613: checking for a thread-safe mkdir -p
    configure:2652: result: /bin/mkdir -p
    configure:2659: checking for gawk
    configure:2675: found /usr/bin/gawk
    configure:2686: result: gawk
    configure:2697: checking whether make sets $(MAKE)
    configure:2719: result: yes
    configure:2748: checking whether make supports nested variables
    configure:2765: result: yes
    configure:2975: checking for gcc
    configure:2991: found /usr/bin/gcc
    configure:3002: result: gcc
    configure:3231: checking for C compiler version
    configure:3240: gcc --version >&5
    gcc (Ubuntu 5.3.1-14ubuntu2.1) 5.3.1 20160413
    Copyright (C) 2015 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    configure:3251: $? = 0
    configure:3240: gcc -v >&5
    Using built-in specs.
    Target: x86_64-linux-gnu
    Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.3.1-14ubuntu2.1' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
    Thread model: posix
    gcc version 5.3.1 20160413 (Ubuntu 5.3.1-14ubuntu2.1) 
    configure:3251: $? = 0
    configure:3240: gcc -V >&5
    gcc: error: unrecognized command line option '-V'
    gcc: fatal error: no input files
    compilation terminated.
    configure:3251: $? = 1
    configure:3240: gcc -qversion >&5
    gcc: error: unrecognized command line option '-qversion'
    gcc: fatal error: no input files
    compilation terminated.
    configure:3251: $? = 1
    configure:3271: checking whether the C compiler works
    configure:3293: gcc -lpthread -levent   conftest.c  >&5
    /usr/bin/ld: cannot find -levent
    collect2: error: ld returned 1 exit status
    configure:3297: $? = 1
    configure:3335: result: no
    configure: failed program was:
    | /* confdefs.h */
    | #define PACKAGE_NAME "libwebsock"
    | #define PACKAGE_TARNAME "libwebsock"
    | #define PACKAGE_VERSION "1.0.7"
    | #define PACKAGE_STRING "libwebsock 1.0.7"
    | #define PACKAGE_BUGREPORT "[email protected]"
    | #define PACKAGE_URL ""
    | #define PACKAGE "libwebsock"
    | #define VERSION "1.0.7"
    | /* end confdefs.h.  */
    | int
    | main ()
    | {
    |   ;
    |   return 0;
    | }
    configure:3340: error: in `/opt/libwebsock-code':
    configure:3342: error: C compiler cannot create executables
    See `config.log' for more details
    ## ---------------- ##
    ## Cache variables. ##
    ## ---------------- ##
    ac_cv_env_CFLAGS_value='-lpthread -levent'
    ac_cv_path_install='/usr/bin/install -c'
    ## ----------------- ##
    ## Output variables. ##
    ## ----------------- ##
    ACLOCAL='${SHELL} /opt/libwebsock-code/missing aclocal-1.15'
    AUTOCONF='${SHELL} /opt/libwebsock-code/missing autoconf'
    AUTOHEADER='${SHELL} /opt/libwebsock-code/missing autoheader'
    AUTOMAKE='${SHELL} /opt/libwebsock-code/missing automake-1.15'
    CFLAGS='-lpthread -levent'
    INSTALL_DATA='${INSTALL} -m 644'
    INSTALL_STRIP_PROGRAM='$(install_sh) -c -s'
    MAKEINFO='${SHELL} /opt/libwebsock-code/missing makeinfo'
    MKDIR_P='/bin/mkdir -p'
    PACKAGE_BUGREPORT='[email protected]'
    PACKAGE_STRING='libwebsock 1.0.7'
    am__tar='$${TAR-tar} chof - "$$tardir"'
    am__untar='$${TAR-tar} xf -'
    install_sh='${SHELL} /opt/libwebsock-code/install-sh'
    ## ----------- ##
    ## confdefs.h. ##
    ## ----------- ##
    /* confdefs.h */
    #define PACKAGE_NAME "libwebsock"
    #define PACKAGE_TARNAME "libwebsock"
    #define PACKAGE_VERSION "1.0.7"
    #define PACKAGE_STRING "libwebsock 1.0.7"
    #define PACKAGE_BUGREPORT "[email protected]"
    #define PACKAGE_URL ""
    #define PACKAGE "libwebsock"
    #define VERSION "1.0.7"
    configure: exit 77

    I hope you can help me fixing that issue. If you need further information, please let me know.

    Best regards,


    opened by Sunacni 4
  • Complete re-write underway

    Complete re-write underway

    I started the initiative quite some time ago to completely re-write libwebsock after Payden's passing. An unexpected international move set me back a bit, but I'm finally settled in across the globe and back in to production. A majority of the core of libwebsock has been entirely re-written, and progress continues to be made on a daily basis. I'm working on it a few hours per a night and have gotten the bulk of it done. I'm anticipating a couple more weeks before a full on beta of 2.0.0 is available for hammering.

    Let me be clear: The rewrite was to add more functionality and clean up the code base to make it "production worthy." Some of the enhancements, and their status, are as follows:

    • Cleaner code base, more organized - One single header is now installed in /usr/local/include (websock.h) - making only the libwebsock API's available to the user. This reduces the overall footprint of the library, and also reduces the amount of crud loaded in to the user code. [ DONE ]
    • libwebsock now has a scheduler - That's right, folks. The original method libwebsock used of spawning a thread per connection and thread per a message would not scale very well. Imagine 200k users connected to the current version of libwebsock all sending multiple messages... That would mean a pthread_create call per a message sent, which could be a little chaotic on the CPU cycles. The scheduler implementation has three separate schedulers now: a connection scheduler to handle incoming connection requests, a dispatcher scheduler to handle dispatching of messages and a control frame scheduler to handle any incoming control frames. Each scheduler has a user defined amount of workers with a default value of 16 (at least, during my testing as my dev box has sixteen cores available to it). [ DONE ]
    • Each client connection now gets tied to an event base on one of the scheduler agent threads. Each thread has its own event base. [ DONE ]
    • Listenserver context addition - libwebsock now easily allows the user to bind the library to their own socket implementation, making integration of libwebsock even simpler in to existing projects. For those who choose, the ability to have libwebsock create a non-blocking port and listen on it is still an option, and has been named a "listen server." [ DONE ]
    • Improved memory management - A GC is under way and in the works for libwebsock to ensure proper memory allocation, tracking and cleanup, allowing future work on libwebsock to reduce the focus on memory management. If a free() is forgotten somewhere, the GC will take care of it. [ In Progress ]
    • Client "tags" - One thing I've seen a lack of understanding in the community on is how to track the sockets to specific clients in a useful manner. It has been required to track and associate connections to specific "people," if you would, within user-land. This is still a feasible option, but libwebsock2 introduces a new "tag" on the client structure. libwebsocket did something similar, but didn't include a way to do anything useful from directly within the library with that tag. libwebsock2 introduces the new libwebsock_send_text_by_tag(); function, as well as a libwebsock_send_binary_by_tag(); function, which will allow you to send to the specific session(s) that have the specified tag. example: libwebsock_send_text_by_tag("jonnywhatshisface", "Private message for Jonny Whatshisface!"); [ DONE ]
    • Memory used per connection greatly reduced - libwebsock pre-2.0 held a LOT of things within the client state context that wasn't really required with the way libwebsock2 is laid out. For instance, the ssl state... The truth is that if SSL is enabled from the context-level, you aren't going to have some clients using SSL and some not. Either you use it, or you don't. [ DONE ]
    • Geared towards threaded applications - The old libwebsock was really intended for use in single threaded applications. The new libwebsock opens up doors for implementation in threaded apps. The contexts now take assignment of the lws_listenserver struct holding the fd and port number of the listen server, be it yours or the built-in one of libwebsock. Please note that the introduction of this new structure serves multiple purposes, one of which is the new type (lws_sockfd) which eliminates issues with pointer truncation on WIN32 platforms. (did I mention more support for WIN32 is under way?) [ DONE ]
    • non-deprecated OpenSSL code - The old version worked fine with SSL, but I'm not a fan of seeing warnings when I compile anything. The OpenSSL implementation caused an endless stream of gawking from my GCC due to deprecated functions. This is no more. [ In Progress ]
    • Support for Sec-WebSocket-Protocol - This was added in and a pull request generated by another user. His addition made it in to libwebsock2, and he has been given credit for it. [ DONE ]
    • uri Support - Yet another contribution from another user in their fork that a PR was generated for. Again, credit was given where credit is due. [ DONE ]
    • Examples - The library is only as good as the examples provided with it for its use. The new release will come with multiple examples, showing usage in the form of chats, instant messaging, file uploads and even use in multi-threaded applications. [ In Progress ]
    • MAN pages! - Yep, there's now libwebsock man pages. They look pretty, too. They outline all the goodies about libwebsock, and all the API calls anyone will ever need. [ In Progress ]
    • Documentation, documentation and more documentation - It's turning in to a real project now. I really wish Payden could be here to see it, but massive contribution to the initial development is heading towards the growth of something great. [ In Progress ]

    Completion Status: All together, it's about 65% complete, and I'm anticipating about another three weeks or so until it's ready for beta testing.

    opened by JonnyWhatshisface 6
Jonathan Hall
Jonathan Hall
BingBing 60 Dec 15, 2022
Pushpin is a reverse proxy server written in C++ that makes it easy to implement WebSocket, HTTP streaming, and HTTP long-polling services.

Pushpin is a reverse proxy server written in C++ that makes it easy to implement WebSocket, HTTP streaming, and HTTP long-polling services. The project is unique among realtime push solutions in that it is designed to address the needs of API creators. Pushpin is transparent to clients and integrates easily into an API stack.

Fanout 3.2k Jan 2, 2023
Cross-platform, efficient, customizable, and robust asynchronous HTTP/WebSocket server C++14 library with the right balance between performance and ease of use

What Is RESTinio? RESTinio is a header-only C++14 library that gives you an embedded HTTP/Websocket server. It is based on standalone version of ASIO

Stiffstream 924 Jan 6, 2023
WSServer is a fast, configurable, and extendable WebSocket Server for UNIX systems written in C (C11).

WSServer a C WebSocket Server WSServer is a fast, configurable, and extendable WebSocket Server for UNIX systems written in C (C11). As of version 2.0

Morten Houmøller Nygaard 170 Dec 8, 2022
🌱Light and powerful C++ web framework for highly scalable and resource-efficient web application. It's zero-dependency and easy-portable.

Oat++ News Hey, meet the new oatpp version 1.2.5! See the changelog for details. Check out the new oatpp ORM - read more here. Oat++ is a modern Web F

Oat++ 6k Jan 4, 2023
Mongoose Embedded Web Server Library - a multi-protocol embedded networking library with TCP/UDP, HTTP, WebSocket, MQTT built-in protocols, async DNS resolver, and non-blocking API.

Mongoose - Embedded Web Server / Embedded Networking Library Mongoose is a networking library for C/C++. It implements event-driven non-blocking APIs

Cesanta Software 9k Jan 1, 2023
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

CppServer Ultra fast and low latency asynchronous socket server & client C++ library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and

Ivan Shynkarenka 958 Jan 3, 2023
websocket and http client and server library, coming with ws, a command line swiss army knife utility

Hello world IXWebSocket is a C++ library for WebSocket client and server development. It has minimal dependencies (no boost), is very simple to use an

Machine Zone, Inc. 369 Jan 5, 2023
Small and fast cross-platform networking library, with support for messaging, IPv6, HTTP, SSL and WebSocket.

frnetlib Frnetlib, is a cross-platform, small and fast networking library written in C++. There are no library dependencies (unless you want to use SS

Fred Nicolson 23 Nov 25, 2022
A Lightweight and fully asynchronous WebSocket client library based on libev

libuwsc(中文) A Lightweight and fully asynchronous WebSocket client library based on libev for Embedded Linux. And provide Lua-binding. Why should I cho

Jianhui Zhao 285 Dec 24, 2022
C++ websocket client/server library

WebSocket++ (0.8.2) WebSocket++ is a header only C++ library that implements RFC6455 The WebSocket Protocol. It allows integrating WebSocket client an

Peter Thorson 6k Jan 8, 2023
This is a small library that allows to stream a Dear ImGui scene to multiple WebSocket clients at once

imgui-ws Dear ImGui over WebSockets This is a small library that allows to stream a Dear ImGui scene to multiple WebSocket clients at once. This is ac

Georgi Gerganov 327 Dec 30, 2022
HTTP and WebSocket built on Boost.Asio in C++11

HTTP and WebSocket built on Boost.Asio in C++11 Branch Linux/OSX Windows Coverage Documentation Matrix master develop Contents Introduction Appearance 3.6k Jan 4, 2023
Custom WebSocket implementation in C for educational and recreational purposes.

C WebSockets WARNING! The library is in an active development state and is not even alpha yet. Use it at your own risk. Nothing is documented, anythin

Tsoding 17 May 25, 2022
Simple embeddable C++11 async tcp,http and websocket serving.

net11 Simple embeddable C++11 async tcp,http and websocket serving. What is it? An easily embeddable C++11 networking library designed to make buildin

Jonas Lund 9 Mar 28, 2020
cuehttp is a modern c++ middleware framework for http(http/https)/websocket(ws/wss).

cuehttp 简介 cuehttp是一个使用Modern C++(C++17)编写的跨平台、高性能、易用的HTTP/WebSocket框架。基于中间件模式可以方便、高效、优雅的增加功能。cuehttp基于boost.asio开发,使用picohttpparser进行HTTP协议解析。内部依赖了nl

xcyl 29 Dec 17, 2022
Various utilities such as WebServer, JSON, WebSocket server, REST framework

DumaisLib This is a library containing several utilities for some projects of Patrick Dumais. Previously, the libraries were all individual but it bec

Patrick Dumais 25 Feb 22, 2022
Header-only, event based, tiny and easy to use libuv wrapper in modern C++ - now available as also shared/static library!

Do you have a question that doesn't require you to open an issue? Join the gitter channel. If you use uvw and you want to say thanks or support the pr

Michele Caini 1.5k Jan 9, 2023