Skip to content
项目

关于

简单、小巧、可嵌入 C++ 项目的 WebSocket Web 服务器。

网站与应用

这些数字如何统计

可以做什么

  • Serves static content from disk
  • API for building WebSocket servers
  • Simple command line binary for quick serving of static files only
  • Supports newer Hybi-10 and Hybi-16 WebSockets as well as the older Hixie style.

实测星标增长

24小时
0
7天
0
15天
正在收集历史
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

Seasocks - A tiny embeddable C++ HTTP and WebSocket server

CI codecov GitHub release License ConanCenter package

Features

  • Simple C++ API
  • Serves static content from disk
  • API for building WebSocket servers
  • Simple command line binary for quick serving of static files only
  • Supports newer Hybi-10 and Hybi-16 WebSockets as well as the older Hixie style.
  • Supports Linux and Windows

Stuff it doesn't do

  • It's not nearly as configurable as Apache, Lighttpd, Nginx, Jetty, etc.
  • It provides only limited support for custom content generation (e.g. Servlets).
  • It has been designed for WebSocket based control.
  • It probably won't work on other systems (patches to support other systems would be welcome, but not a priority for us)

Intended use and security

Seasocks is for internal tools and trusted environments: control and monitoring UIs, embedded devices, development and test setups. It is not designed for untrusted environments, and it should not be exposed directly to the internet.

It has no TLS support, any authentication is left to your own handlers, and security hardening is not a goal of the project. Some basic safeguards exist (for example, static file requests can't climb out of the static directory with ..), but its request handling isn't designed to withstand hostile clients, so assume that one on the network can cause trouble. If you need to serve untrusted clients, put Seasocks behind a reverse proxy (nginx, Caddy, etc.) that provides TLS, authentication and request limits.

Getting started

Check out the tutorial on the wiki.

See src/app/c/ws_test.cpp for an example.

Using Seasocks in your CMake project

Seasocks needs a C++17 compiler.

Installed

Configure, build and install Seasocks:

cmake -S . -B build -DUNITTESTS=OFF -DSEASOCKS_EXAMPLE_APP=OFF
cmake --build build
cmake --install build --prefix <dir>

Without --prefix the install goes to /usr/local, which usually needs root, so a directory you can write to is normally what you want. This installs the library, the public headers under include/seasocks, the Seasocks CMake package files under lib/cmake/Seasocks, and the LICENSE.

Then find it and link against the Seasocks::seasocks target, adding the prefix to CMAKE_PREFIX_PATH (for example -DCMAKE_PREFIX_PATH=<dir>) if it is not a standard location:

find_package(Seasocks REQUIRED)
add_executable(my_server serve.cpp)
target_compile_features(my_server PRIVATE cxx_std_17)
target_link_libraries(my_server PRIVATE Seasocks::seasocks)

Built as part of your project

Each of these builds Seasocks alongside your code, so there is nothing to install. The link line is always the same as above.

With add_subdirectory on a copy of the source (for example a git submodule in thirdparty/seasocks):

set(UNITTESTS OFF CACHE INTERNAL "")
set(SEASOCKS_EXAMPLE_APP OFF CACHE INTERNAL "")
add_subdirectory(thirdparty/seasocks)
target_compile_features(my_server PRIVATE cxx_std_17)
target_link_libraries(my_server PRIVATE Seasocks::seasocks)

With FetchContent:

include(FetchContent)
set(UNITTESTS OFF CACHE INTERNAL "")
set(SEASOCKS_EXAMPLE_APP OFF CACHE INTERNAL "")
FetchContent_Declare(seasocks
    GIT_REPOSITORY https://github.com/mattgodbolt/seasocks.git
    GIT_TAG v1.4.6)
FetchContent_MakeAvailable(seasocks)
target_compile_features(my_server PRIVATE cxx_std_17)
target_link_libraries(my_server PRIVATE Seasocks::seasocks)

With CPM.cmake:

CPMAddPackage(
    NAME seasocks
    GITHUB_REPOSITORY mattgodbolt/seasocks
    GIT_TAG v1.4.6
    OPTIONS "UNITTESTS OFF" "SEASOCKS_EXAMPLE_APP OFF")
target_compile_features(my_server PRIVATE cxx_std_17)
target_link_libraries(my_server PRIVATE Seasocks::seasocks)

Seasocks is built as a static library unless you set SEASOCKS_SHARED=ON (or BUILD_SHARED_LIBS=ON). Deflate support is on by default and requires zlib; configure with -DDEFLATE_SUPPORT=OFF to build without it. Projects linking a static, deflate-enabled install need zlib to be findable too.

探索相关项目

加载中…