GithubHelp home page GithubHelp logo

bluebrain / rockets Goto Github PK

View Code? Open in Web Editor NEW
39.0 14.0 8.0 1.36 MB

REST and websockets C++ library

License: GNU Lesser General Public License v3.0

CMake 0.67% C++ 82.67% JavaScript 0.22% TypeScript 10.69% Shell 0.07% Makefile 0.29% Python 5.39%
cpp websocket-library rest-server http json json-rpc json-schema websocket websocket-server websocket-client

rockets's Introduction

Rockets

A library for easy HTTP and websockets messaging in C++ applications.

Travis CI Language grade: C/C++

Table of Contents

Features

Rockets provides the following features:

Build

Rockets is a cross-platform library designed to run on any modern operating system, including all Unix variants. It requires a C++11 compiler and uses CMake to create a platform specific build environment. The following platforms and build environments are tested:

  • Linux: Ubuntu 16.04, 18.04
  • Mac OS X: 10.9 - 10.14

Rockets requires the following external, pre-installed dependencies:

Building from source is as simple as:

git clone --recursive https://github.com/BlueBrain/Rockets.git
mkdir Rockets/build
cd Rockets/build
cmake -GNinja ..
ninja

Usage

Hello world REST server

#include <rockets/server.h>
#include <iostream>

int main(int , char** )
{
    rockets::Server server;
    std::cout << "Rockets REST server running on " << server.getURI() << std::endl;

    server.handle(rockets::http::Method::GET, "hello", [](auto) {
        return rockets::http::make_ready_response(rockets::http::Code::OK, "world");
    });
    for(;;)
        server.process(100);
    return 0;
}

Hello world websockets server

#include <rockets/server.h>
#include <iostream>

int main(int , char** )
{
    rockets::Server server("", "myws");
    std::cout << "Rockets websockets server running on " << server.getURI() << std::endl;

    server.handleText([](const auto& request) {
        return "server echo: " + request.message;
    });
    for(;;)
        server.process(100);
    return 0;
}

Production REST server example

For a more elaborate use of a Rockets REST server, check out the RestServer of Tide.

Production websockets server example

For a more elaborate use of a Rockets websockets server, check out the RocketsPlugin of Brayns.

Contribute

Follow the next guidelines when making a contribution:

  • Install our pre-commit hooks with pre-commit install prior the first commit
  • Use Conventional Commits spec whenever making a commit
  • Keep PRs to a single feature or fix

Funding & Acknowledgment

The development of this software was supported by funding to the Blue Brain Project, a research center of the École polytechnique fédérale de Lausanne (EPFL), from the Swiss government’s ETH Board of the Swiss Federal Institutes of Technology.

Copyright (c) 2021 Blue Brain Project/EPFL

License

Rockets is licensed under the LGPL version 3, unless noted otherwise, e.g., for external dependencies. See file LICENSE.txt for the full license. External dependencies are either LGPL or BSD-licensed. See file ACKNOWLEDGEMENTS.txt and AUTHORS.txt for further details.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3 as published by the Free Software Foundation.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

rockets's People

Contributors

jplanasc avatar karjonas avatar nadirrogue avatar ppodhajski avatar tribal-tec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rockets's Issues

Add support for subscriptions

Currently, all events broadcasted from the server are sent over the wire to all clients. While this is expected behaviour, it is sometimes undesirable.

I propose using the pub/sub pattern where clients can subscribe to specific RPC methods and only receive messages for those methods that the client subscribed to.

By default, the server, would send messages for a specific method only to the clients that subscribed to that method.

E.g. of subscribe RPC:

{
    "jsonrpc": "2.0",
    "method": "subscribe", // "unsubscribe" when user don't want messages for the method anymore
    "params": {
        "method": "SOME_METHOD"
    }
}

Potential dependency conflicts between rockets and coverage

Hi, as shown in the following full dependency graph of rockets, rockets requires coverage <4.6,>=4.5.2, rockets requires nose-xcover <1.1,>=1.0.11 (nose-xcover 1.0.11 will be installed, i.e., the newest version satisfying the version constraint), and directed dependency nose-xcover 1.0.11 transitively introduces coverage >=3.4.

Obviously, there are multiple version constraints set for coverage in this project. However, according to pip's “first found wins” installation strategy, coverage 4.5.4 (i.e., the newest version satisfying constraint <4.6,>=4.5.2) is the actually installed version.

Although the first found package version coverage 4.5.4 just satisfies the later dependency constraint (coverage <4.6,>=4.5.2), such installed version is very close to the upper bound of the version constraint of coverage specified by nose-xcover 1.0.11.

Once nose-xcover upgrades,its newest version will be installed, Therefore, it will easily cause a dependency conflict (build failure), if the upgraded nose-xcover version introduces a higher version of coverage, violating its another version constraint <4.6,>=4.5.2.

According to the release history of nose-xcover, it habitually upgrates Coverage in its recent releases. For instance, nose-xcover 1.0.4 upgrated Coverage’s constraint from <=3.3 to <=3.4,nose-xcover 1.0.5 upgrated Coverage’s constraint from <=3.4 to ==3.4 ,and nose-xcover 1.0.7 upgrated Coverage’s constraint from ==3.4 to >=3.4.

As such, it is a warm warning of a potential dependency conflict issue for rockets.

Dependency tree

rockets - 1.0.2
| +- coverage(install version:4.5.4 version range:<4.6,>=4.5.2)
| +- json-rpc(install version:1.13.0 version range:<12,>=1.11.1)
| +- jsonrpcserver(install version:3.5.6 version range:<3.6,>=3.5.6)
| | +- funcsigs(install version:1.0.2 version range:<2,>=1)
| | +- jsonschema(install version:2.6.0 version range:<3,>=2)
| | +- six(install version:1.14.0 version range:<2,>=1)
| +- nbsphinx(install version:0.4.3 version range:<0.5,>=0.4.1)
| | +- docutils(install version:0.16 version range:*)
| | +- jinja2(install version:2.11.2 version range:*)
| | | +- MarkupSafe(install version:2.0.0a1 version range:>=0.23)
| +- nose(install version:1.3.7 version range:<1.4,>=1.3.7)
| +- nosexcover(install version:1.0.11 version range:<1.1,>=1.0.11)
| | +- coverage(install version:4.5.4 version range:>=3.4)
| | +- nose(install version:1.3.7 version range:*)
| +- pandoc(install version:1.0.2 version range:<1.1,>=1.0.2)
| +- pycodestyle(install version:2.4.0 version range:<2.5,>=2.4.0)
| +- pydocstyle(install version:5.0.2 version range:<31,>=3.0.0)
| | +- snowballstemmer(install version:2.0.0 version range:*)
| +- pylint(install version:2.5.2 version range:<3,>=2.2.2)
| +- rx(install version:1.6.1 version range:<1.7,>=1.6.1)
| +- sphinx(install version:1.8.5 version range:<1.9,>=1.8.3)
| | +- alabaster(install version:0.7.12 version range:<0.8,>=0.7)
| | +- babel(install version:2.8.0 version range:>=1.3)
| | | +- pytz(install version:2019.3 version range:>=2015.7)
| | +- docutils(install version:0.16 version range:>=0.11)
| | +- imagesize(install version:1.2.0 version range:*)
| | +- jinja2(install version:2.11.2 version range:>=2.3)
| | | +- MarkupSafe(install version:2.0.0a1 version range:>=0.23)
| | +- packaging(install version:20.3 version range:*)
| | +- pygments(install version:2.6.1 version range:>=2.0)
| | +- requests(install version:2.23.0 version range:>=2.0.0)
| | | +- certifi(install version:2020.4.5.1 version range:>=2017.4.17)
| | | +- chardet(install version:3.0.4 version range:>=3.0.2,<4)
| | | +- idna(install version:2.9 version range:>=2.5,<3)
| | | +- urllib3(install version:1.25.9 version range:>=1.21.1,<1.26)
| | +- setuptools(install version:46.1.3 version range:*)
| | +- six(install version:1.14.0 version range:>=1.5)
| | +- snowballstemmer(install version:2.0.0 version range:>=1.1)
| | +- sphinxcontrib-websupport(install version:1.2.1 version range:*)
| +- sphinx-rtd-theme(install version:0.4.3 version range:<0.5,>=0.4.2)
| | +- sphinx(install version:1.8.5 version range:*)
| | | +- alabaster(install version:0.7.12 version range:<0.8,>=0.7)
| | | +- babel(install version:2.8.0 version range:>=1.3)
| | | | +- pytz(install version:2019.3 version range:>=2015.7)
| | | +- docutils(install version:0.16 version range:>=0.11)
| | | +- imagesize(install version:1.2.0 version range:*)
| | | +- jinja2(install version:2.11.2 version range:>=2.3)
| | | | +- MarkupSafe(install version:2.0.0a1 version range:>=0.23)
| | | +- packaging(install version:20.3 version range:*)
| | | +- pygments(install version:2.6.1 version range:>=2.0)
| | | +- requests(install version:2.23.0 version range:>=2.0.0)
| | | | +- certifi(install version:2020.4.5.1 version range:>=2017.4.17)
| | | | +- chardet(install version:3.0.4 version range:>=3.0.2,<4)
| | | | +- idna(install version:2.9 version range:>=2.5,<3)
| | | | +- urllib3(install version:1.25.9 version range:>=1.21.1,<1.26)
| | | +- setuptools(install version:46.1.3 version range:*)
| | | +- six(install version:1.14.0 version range:>=1.5)
| | | +- snowballstemmer(install version:2.0.0 version range:>=1.1)
| | | +- sphinxcontrib-websupport(install version:1.2.1 version range:*)
| +- tox(install version:3.6.1 version range:<3.7,>=3.6.1)
| | +- filelock(install version:3.0.12 version range:>=3.0.0,<4)
| | +- pluggy(install version:0.13.1 version range:>=0.3.0,<1)
| | | +- importlib-metadata(install version:1.6.0 version range:>=0.12)
| | +- py(install version:1.8.1 version range:<2,>=1.4.17)
| | +- setuptools(install version:46.1.3 version range:>=30.0.0)
| | +- six(install version:1.14.0 version range:<2,>=1.0.0)
| | +- toml(install version:0.10.0 version range:>=0.9.4)
| | +- virtualenv(install version:20.0.17 version range:>=1.11.2)
| +- websockets(install version:7.0 version range:<8,>=7.0)

Thanks for your help.
Best,
Neolith

Initial Update

The bot created this issue to inform you that pyup.io has been set up on this repo.
Once you have closed it, the bot will open pull requests for updates as soon as they are available.

cmake fails

Not configured Rockets: Required OpenSSL not found

MacOS catalina, libwebsockets installed

Websockets are not working

In Ubuntu 19.04 websockets seems not to work at all. rockets::Server::handleOpen is never called even on the webbrowser client says the websocket will open successfully. HTTP works (rockets::Server::handle for GET is called)

In JS
"var uri = "ws://127.0.0.1:8080/telex";
var socket = new WebSocket(uri);
socket.onopen = function(event) {
console.log("onopen", uri, event);
}"

I construct rockets::Server as m_server(":" + std::to_string(port), "telex", ThreadCount) ... it does not matter if ThreadCount is 0 or 8 (if 0 I call Server::process() to poll) - HTTP works fine, websockets do nothing. I cannot debug libwebsockets so I have no clue what is going on there.

I wrote a simple websocket server using Python, it works (with or without "telex")

libuv support broken on Ubuntu 16.04 and with libwebsockets 3.0

  • Ubuntu 16.04 with libuv 0.10-dev
  • Compiled libwebsockets v3.0-stable with LWS_WITH_LIBUV=ON

Two functions are missing, one in libuv and one in lws 3.0:

  1. ../Rockets/rockets/serverContext.cpp:59:63: error: ‘uv_loop_alive’ was not declared in this scope
    const bool uvLoopRunning = uvLoop && uv_loop_alive(uvLoop_) != 0;

  2. ../Rockets/rockets/serverContext.cpp:92:44: error: ‘lws_uv_initloop’ was not declared in this scope
    lws_uv_initloop(context, uvLoop_, 0);

lws 3.0 API: https://libwebsockets.org/lws-api-doc-v3.0-stable/html/group__uv.html

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.