Skip to content

Pusher++ is a header-only cross-platform C++ library for connecting to Pusher

License

Notifications You must be signed in to change notification settings

BenPope/pusher-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pusher client and server built on Boost.Asio

Contents

Introduction

Pusher++ is a header-only cross-platform C++ library for connecting to Pusher. It's built on top of Boost.Asio via Boost.Beast for HTTP and Websocket support.

Features

  • Performance. Supports both synchronous and asynchronous APIs.
  • SSL support. Connect securely to endpoints at Pusher and bypass problematic proxies.
  • Symmetric API Client and Server share the same API.

Usage

These examples are complete, but you will have to set your application specific credentials. The examples directory contains examples that parse the command line.

Example Server:

#include <pusher++/server.hpp>
#include <iostream>

int main()
{
    std::string const app_id = "Your App ID";
    std::string const secret = "Your Secret";
    std::string const key = "Your Key";
    
    boost::asio::io_service ios;
    pusher::server<boost::asio::ip::tcp::socket> server{ios, app_id, key, secret};
    server.connect();

    std::string input;
    while(input != "bye" && std::cout << "\nMessage: " && std::getline(std::cin, input))
    {
        std::cout << server.trigger("test_channel", "test_name", input);
    }
    ios.run();
}

Example Client:

#include <pusher++/client.hpp>
#include <iostream>

int main(int argc, char* argv[])
{
    std::string const key = "Your Key";
    
    boost::asio::io_service ios;
    pusher::client<boost::asio::ip::tcp::socket> client{ios, key};
    client.connect();
    
    client.bind_all([](pusher::event const& event)
    {
        std::cout << event.data << '\n';
    });

    auto test_channel = client.channel("test_channel");
    test_channel.bind("test_name", [&client](pusher::event const& event)
    {
        if(event.data == "bye")
            client.disconnect();
    });
    ios.run();
}

Requirements

Build

This is a header only library, no building is required.

However, a cmake build system is in place for tests and examples. Currently, it is assumed that the environment is the environment is linux-ish and that Boost and OpenSSL headers are installed; other dependencies are managed by cmake. Building on Windows should work, but is untested and will likely require some minor changes to find Boost and OpenSSL.

mkdir -p build && cd build && cmake .. && make -j

Status

Caveat emptor. This is very early work; it's incomplete and has not been used in anger. Everything is subject to change, but it may not be completed or even maintained.

However, you are free to use it under the terms set out below.

Licence

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

Contact

Please report issues or questions here: https://github.com/BenPope/pusher-cpp/issues

About

Pusher++ is a header-only cross-platform C++ library for connecting to Pusher

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published