How to write C++ SignalR client to connect a C# SiganlR server
Asked Answered
R

1

8

I am aware of communication between a C# server and C# client using SignalR. Along with C# client, I have C++ client apps where I need to communicate with the same C# server that is used to communicate with C# clients.

For communication between C# server(console application) and C# clients(Desktop) i followed the approach in SignalR Desktop approach

In the above link it is very clear how do we establish a connection to hub and communicate with the server. Similarly I want to have MFC application as client and I want send some messages to the MFC client from C# server. I don't have any idea like how do i establish a connection from MFC app. I don't know whether it is possible or not.

Could anyone please help with a sample on how C++ signalR client connects to a C# client.

Ritualism answered 6/10, 2017 at 4:6 Comment(2)
Can you please elaborate your question with the things you tried :)Fang
@Volka, Added more description in detail.Ritualism
D
8

Actually, a SignalR C++ client already exists. If you are on Windows you can use NuGet to get the package. There are different packages depending on the toolset used to build the code (important because of the runtime the client is linked against) - v120 uses toolset shipped in VS2013, v140 uses toolset from VS2015. For instance https://www.nuget.org/packages/Microsoft.AspNet.SignalR.Client.Cpp.v140.WinDesktop/1.0.0-beta2 is a package for desktop apps built with VS2015. I wrote a post on how to use the client as well as a miniseries on using cpprestsdk (a.k.a. Casablanca) - a library which provides async functionality in C++. You need to know this stuff to be able to consume the client since it returns tasks (think promises). The code also compiles on Linux (and I heard it can be compiled on MacOS but I personally haven't done it).

Disunity answered 6/10, 2017 at 4:39 Comment(8)
Thanks for your reply. I have seen your post, i will try it out and if any doubt will get back to you.Ritualism
I've being trying to use it with VS 2109 without success. Any update for this?Grovergroves
AFAICT the packages were not updated to support VS2019.Disunity
Thanks, @Pawel. Do you know how I can connect to signalR using C++ in VS2019? Thanks again.Grovergroves
I believe you would have to get the sources and recompile with VS2019 making necessary changes. I think the first hurdle to overcome will be to get the right (i.e. VS2019 compatible) cpprestsdk (build or get one from NuGet if one exist) and then update build files to use new PlatformToolset and VS.Disunity
Does this library connect to signalr .net core server ?Neisse
@Neisse - no, this one will not work with .NET CoreDisunity
Thank you so much for information @Disunity i think this one connects to .net core. github.com/aspnet/SignalR-Client-CppNeisse

© 2022 - 2024 — McMap. All rights reserved.