Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

C++ Client for ASP.NET Core SignalR

License

NotificationsYou must be signed in to change notification settings

aspnet/SignalR-Client-Cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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

Install this library

Warning

Websockets are currently disabled which means the client will fail to connect to a SignalR server.Workaround by providing a custom websocket client implementation and using it viabuilder.with_websocket_factory(...).A new websocket implementation will be provided in-box in a future commit.

There are multiple ways to build this library

  • Currently missing due to websocket issues.Usevcpkg and install the library withvcpkg install microsoft-signalr
  • Build fromcommand 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 lineDescriptionDefault value
-DBUILD_SAMPLESBuild the included sample projectfalse
-DBUILD_TESTINGBuilds the test projecttrue
-DUSE_CPPRESTSDKIncludes the CppRestSDK (default http stack) (requires cpprestsdk to be installed)false
-DUSE_MSGPACKAdds an option to use the MessagePack Hub Protocol (requires msgpack to be installed, e.g.vcpkg install msgpack:x64-windows)false
-DWERROREnables warnings as errorstrue
-DWALLEnables all warningstrue
-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--initPS> .\submodules\vcpkg\bootstrap-vcpkg.batPS> .\submodules\vcpkg\vcpkg.exe install cpprestsdk:x64-windows jsoncpp:x64-windowsPS> mkdir build.releasePS> cd build.releasePS> cmake ..-A x64-DCMAKE_TOOLCHAIN_FILE="..\submodules\vcpkg\scripts\buildsystems\vcpkg.cmake"-DCMAKE_BUILD_TYPE=Release-DUSE_CPPRESTSDK=truePS> cmake--build.--config Release

Output will be inbuild.release\bin\Release\

Build on Mac

$ git submodule update --init$ brew install gcc6$ ./submodules/vcpkg/bootstrap-vcpkg.sh$ ./submodules/vcpkg/vcpkg install cpprestsdk jsoncpp$ 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 inbuild.release/bin/

Build on Linux

$ git submodule update --init$ ./submodules/vcpkg/bootstrap-vcpkg.sh$ ./submodules/vcpkg/vcpkg install cpprestsdk boost-system boost-chrono boost-thread jsoncpp$ 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 inbuild.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")//.with_messagepack_hub_protocol()//.with_websocket_factory(...)//.with_http_client_factory(...)    .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)

About

C++ Client for ASP.NET Core SignalR

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors20


[8]ページ先頭

©2009-2025 Movatter.jp