Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 324
Siva Avatar asked Oct 06 '17 04:10

Siva


People also ask

How do I send client specific messages using SignalR?

public async Task BroadcastToUser(string data, string userId) => await Clients. User(userId). SendAsync("broadcasttouser", data); Remember that when we are sending messages to a user, they will be sent to all connections associated with that user and not just any particular connection.


1 Answers

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).

like image 135
Pawel Avatar answered Jan 01 '23 09:01

Pawel