C++ Client for ASP.NET Core SignalR
Перейти к файлу
Tzu Huan Tai 5552361b93
Fix exception message (#84)
2022-07-11 08:59:15 -07:00
.azure Update to Ubuntu 18 (#63) 2021-07-22 19:16:57 -07:00
docs Add document for releasing the library (#68) 2021-08-06 15:00:49 -07:00
eng Update Arcade and run SDL (#54) 2021-03-31 12:43:17 -07:00
include/signalrclient Add support for pinging (#77) 2022-03-08 10:07:52 -08:00
samples/HubConnectionSample Use std::vector for 'send' and 'on' to make it clear there can be multiple arguments/parameters (#65) 2021-08-05 18:41:47 -07:00
src/signalrclient Fix exception message (#84) 2022-07-11 08:59:15 -07:00
submodules Update vcpkg (#82) 2022-04-20 13:29:35 -07:00
test Fix exception message (#84) 2022-07-11 08:59:15 -07:00
third_party_code Update README and remove unused files (#40) 2021-01-25 19:45:55 -08:00
.gitignore Add support for open folder in VS for local dev (#6) 2019-07-09 15:11:25 -07:00
.gitmodules Initial client merge (#2) 2019-04-02 12:14:15 -07:00
CMakeLists.txt Update CMake version (#69) 2021-08-09 11:20:11 -07:00
CMakeSettings.json Add MessagePack support (#53) 2021-05-17 21:01:05 -07:00
CODE-OF-CONDUCT.md Link Code of Conduct (#30) 2020-04-09 12:42:26 -07:00
Directory.Build.props Add arcade to repo (#21) 2019-12-04 13:21:34 -08:00
Directory.Build.targets Add arcade to repo (#21) 2019-12-04 13:21:34 -08:00
LICENSE.txt Update license (#29) 2020-03-03 10:12:06 -08:00
NuGet.config Fixup feeds (#45) 2021-02-09 16:03:54 -08:00
README.md Update vcpkg (#82) 2022-04-20 13:29:35 -07:00
azure-pipelines.yml Update vcpkg (#82) 2022-04-20 13:29:35 -07:00
global.json Add arcade to repo (#21) 2019-12-04 13:21:34 -08:00
run-tests.sh Add scheduler abstraction + default impl (#35) 2021-04-14 08:54:49 -07:00
startvs.cmd Add support for open folder in VS for local dev (#6) 2019-07-09 15:11:25 -07:00
third-party-notices.txt Change Json library (#18) 2019-11-23 13:23:56 -08:00

README.md

ASP.NET Core SignalR C++ Client

This project is part of ASP.NET Core. You can find samples, documentation and getting started instructions for ASP.NET Core at https://github.com/aspnet/AspNetCore.

Use https://github.com/aspnet/AspNetCore/issues for issues with this project.

Install this library

There are multiple ways to build this library

  • Use vcpkg and install the library with vcpkg install microsoft-signalr
  • Build from command line
  • Build in Visual Studio (must have the "Desktop Development with C++" workload) by selecting the "Open a local folder" option and selecting the repository root folder

Command line build

Below are instructions to build on different OS's. You can also use the following options to customize the build:

Command line Description Default value
-DBUILD_SAMPLES Build the included sample project false
-DBUILD_TESTING Builds the test project true
-DUSE_CPPRESTSDK Includes the CppRestSDK (default http stack) (requires cpprestsdk to be installed) false
-DUSE_MSGPACK Adds an option to use the MessagePack Hub Protocol (requires msgpack-c to be installed) false
-DINCLUDE_JSONCPP Builds jsoncpp source code as part of the output binary true
-DWERROR Enables warnings as errors true
-DWALL Enables all warnings true
-DINJECT_HEADER_AFTER_STDAFX=<header path> Adds the provided header to the library compilation in stdafx.cpp, intended to allow "new" and "delete" to be replaced. <none>

Build on Windows

PS> git submodule update --init
PS> .\submodules\vcpkg\bootstrap-vcpkg.bat
PS> .\submodules\vcpkg\vcpkg.exe install cpprestsdk[websockets]:x64-windows
PS> mkdir build.release
PS> cd build.release
PS> cmake .. -A x64 -DCMAKE_TOOLCHAIN_FILE="..\submodules\vcpkg\scripts\buildsystems\vcpkg.cmake" -DCMAKE_BUILD_TYPE=Release -DUSE_CPPRESTSDK=true
PS> cmake --build . --config Release

Output will be in build.release\bin\Release\

Build on Mac

$ git submodule update --init
$ brew install gcc6
$ ./submodules/vcpkg/bootstrap-vcpkg.sh
$ ./submodules/vcpkg/vcpkg install cpprestsdk[websockets]
$ mkdir build.release
$ cd build.release
$ cmake .. -DCMAKE_TOOLCHAIN_FILE=../submodules/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=Release -DUSE_CPPRESTSDK=true
$ cmake --build . --config Release

Output will be in build.release/bin/

Build on Linux

$ git submodule update --init
$ ./submodules/vcpkg/bootstrap-vcpkg.sh
$ ./submodules/vcpkg/vcpkg install cpprestsdk[websockets] boost-system boost-chrono boost-thread
$ mkdir build.release
$ cd build.release
$ cmake .. -DCMAKE_TOOLCHAIN_FILE=../submodules/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=Release -DUSE_CPPRESTSDK=true
$ cmake --build . --config Release

Output will be in build.release/bin/

Example usage

#include <iostream>
#include <future>
#include "signalrclient/hub_connection.h"
#include "signalrclient/hub_connection_builder.h"
#include "signalrclient/signalr_value.h"

std::promise<void> start_task;
signalr::hub_connection connection = signalr::hub_connection_builder::create("http://localhost:5000/hub").build();

connection.on("Echo", [](const std::vector<signalr::value>& m)
{
    std::cout << m[0].as_string() << std::endl;
});

connection.start([&start_task](std::exception_ptr exception) {
    start_task.set_value();
});

start_task.get_future().get();

std::promise<void> send_task;
std::vector<signalr::value> args { "Hello world" };
connection.invoke("Echo", args, [&send_task](const signalr::value& value, std::exception_ptr exception) {
    send_task.set_value();
});

send_task.get_future().get();

std::promise<void> stop_task;
connection.stop([&stop_task](std::exception_ptr exception) {
    stop_task.set_value();
});

stop_task.get_future().get();

Example CMake file

cmake_minimum_required (VERSION 3.5)
project (signalrclient-sample)

find_package(microsoft-signalr REQUIRED)
link_libraries(microsoft-signalr::microsoft-signalr)

add_executable (sample sample.cpp)