SignalR client for Ruby - asp.net

I have a task for my project to connect to ASP.NET SignalR websocket to fetch some data in real-time from Ruby program. The problem is I couldn't find any single SignalR client for Ruby. As I understand, SignalR version of websockets is a bit different from e.g. socket.io, there are some instances called "Hubs", so I guess special client is needed.
Can I connect to SignalR websocket from Ruby using any existing solutions, or do I need to write client from scratch?

Yes, you are right. Signalr server side is called Signalr hub and each client will be connected to this hub. Using socket.io client is not possible and you need a client supporting Signalr protocol.Unfortunately, there are no ruby projects or at least well-maintained ones right now.
You can implement a one which is sure not an overnight work or use a hack such as host an existing signalr client and talk to your ruby client from there.

Related

Is it possible to use SignalR to forward data from another server to your clients?

My previous experience with SignalR was only as a server, getting data from a database and then updating the webpages accordingly.
I was wondering if it is possible to use SignalR to connect to other servers that shares data via Websockets and then consolidating the data to send out to your own clients, also using SignalR? So something like a forwarder of sorts.
You can use the .net signalR client to hook nearly anything to the server. There can be difficulties with waking the server up, so it is important to check the behavior.
https://learn.microsoft.com/en-us/aspnet/core/signalr/dotnet-client?view=aspnetcore-5.0&tabs=visual-studio

SignalR Core scaling/hosting

I have some questions regarding SignalR Core on the server side;
My server is written in ASP.NET Core, and it uses SignalR for sending notifications to users. The server uses Controllers with endpoints that clients interact with.
1) Can I host the entire thing in Azure App Service and add the SignalR service to it? Or would it be better to split the SignalR code out to its own server, which is called from the "main" server when needed?
2) The SignalR Service has an option for "Serverless", which according to documentation doesn't support clients calling any server RPCs when in said mode. Could I run this thing in Serverless mode as I'm only using the sockets for sending notifications to the clients. Or is it reserved for Azure functions?
3) Is there a way to get the number of connections for a user in a SignalR hub? I would like to send a push message to the user if he doesn't have any connections to the server. If not - what is the recommended way of handling this? I was thinking of adding a singleton service that keeps count, but am unsure if this would work at scale, especially with the SignalR service.
Thanks.
1) Better use the Azure SignalR.
2) Use it with the hub.
3) If you use Azure SignalR, you can just see it from the portal. In the code, whenever you use Azure SignalR or not, you can save the user Id in some var and count the connections. If you have multiple hubs and servers, you need to do more (if using redis-backplane for example).

When we should use SignalR self hosted and when we should not?

I am in a stage of using SignalR in my project and i don't understand when to use Self hosted option and when we should not use. As a example if I am willing to host my web application in server farm,
There will be separate hosting servers
Separate SignalR hubs in each IIS server
If we want to broadcast message into each client, how this is working in SignalR
The idea with SignalR running in multiple instances is that clients connected on instance A cannot get messages from clients connected to instance B.
(SignalR scaleout documentation)
However, when you scale out, clients can get routed to different
servers. A client that is connected to one server will not receive
messages sent from another server.
The solution to this is using a backplane - everytime a server recieves a message, it forwards it to all other servers. You can do this using Azure Service Bus, Redis or SQL.
The way I see, you use the self host option when you either don't want the full IIS running (because you have some lightweight operations that don't require all IIS heaviness) or you don't want a web server at all (for example you want to add real-time functionality to an already existing let's say forms application, or in any other process).
Be sure to read the documentation for self-hosting SignalR and decide whether you actually need to self host SignalR.
If you are developing a web application under IIS, I don't see any reason why you would want to self-host SignalR.
Hope this helps. Best of luck!

SignalR server API, and other platforms

I like SignalR and I am developing 2 things.
Server side code
Client web app
The challenge is that I need to allow the server to be implemented in a non .NET environments like may be Java or PHP. In that case the client will be using
"SignalR" libraries and server has to match the SignalR implementation on the server (in PHP, Java, etc). In a way, what I am after is shipping a server side API and a .NET signalr based implementation, but allow anyone to be able to implement the server side API in php/java etc
For this, what I need the API sequence and protocol signalR uses. I am kind of thinking that this is not going to happen because SignalR is matched on the client and server side to talk in specific way to make the magic possible.
Has anyone else been in this predicament? Any ideas on what the best way to proceed? By the way, before you ask the question, if it is a pure websockets based app, I will have less problems, I can just user WebSockets standard APIs.
However, I might need to fallback on long polling, because my server might need to run on Windows 7 - where websockets is not available.
Instead of reverse engineer the SignalR protocol make sure the clients do not have direct dependency on SignalR. Create client side adapters for the different server side framework. Include the correct adapter depending on server side platform
Here is a description of the SignalR protocol.

SignalR Persistent Connection Between MVC Server and a Windows Service?

I have a use case where we will have an ASP.NET MVC Server Application but it needs to talk over a persistent connection to a Windows service. It doesn't look like SignalR does this as it really wants talk Server to JavaScript browsers but I did notice .NET desktop libraries. Can it talk from a server to a Windows server? If not, is there a recommended way, TCP/IP or HTTP to have a persistent connection between the two? NetTcpBinding in WCF?
Yes, there is a SignalR client library for .NET that you can use in any old .NET app to talk to a SignalR server just like you can from JavaScript.
While there is a WebSockets binding for WCF, there is no binding that actually talks native SignalR which adds its own message framing on top of raw web sockets. So, while possible, it doesn't exist today and I wouldn't hold my breath for it ever being created.
Why not simply have a queue using RabbitMQ. And anytime the web need to talk to window service, it push a message into the queue while the window service listen to the queue

Resources