Send notification to other browsers with Blazor - signalr

I am writing a blazor server application.
I have a textbox+button in a page and a grid. What i want to do is to allow users to type some text in the texbox. The text should be added to the grid.
What i want is to automatically refresh grid on all browsers when a new message is typed.
I have tried and manage to do that with signalr and signalr hub. It works like a charm.
But i am wondering something: Blazor server creates a signalr connexion between server and browser. My signalr hub is creating a second signalr connexion.
Is there a way to do that without creating a second signalr connexion.
In other words, is there a way to send notifications to browsers without a signalr hub ?
Thanks

I don't know if my view of your problem is correct.
I suspect you're trying to create a direct Signalr connection point-to-point between clients, without any centralized hub.
Right?
If this is the case I think it's impossible using only Signalr, because the server maintains a list of clients ip/port connected to the hub and this list isn't shared between clients.
I don't know if there is any kind of project based on Signalr that enable a Blazor WASM application to expose itself as a server in order to receive communication directly from other WASM Client, but in the world of gaming all is possible !

Related

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!

Where to host SignalR when long-running service via WCF is backend

I'm sure that was a confusing enough title.
I have a long running Windows service dealing with things happening in the world. This service is my canonical source of truth for the rest of my system. Now I want to slap a web interface onto this so the clients can see what is actually going on. At first this would simply be a MVC5 application with some Web API stuff. Then I plan to use SignalR 2.0 and Ember.js to make this application more interactive and "realtime".
The client communicates with the Windows Service over named pipes using WCF. A client (such as a web app) could request an instance of for example IEventService, would be given a WCF proxy client, and could read about events through this interface. Simple enough.
However, a web application basically just exists in the sense that it responds to requests from the user. The way I understand it, this is not the optimal environment for a long lived WCF client proxy to raise events in, and thus I wonder how to host my SignalR stuff. Keep in mind that a user would log in to the MVC5 site, but through the magic of SignalR, they will keep interacting with the service without necessarily making further requests to the website.
The way I see it, there are two options:
1) Host SignalR stuff as part of the web app. Find a way to keep it "long-running" while it has active clients, so that it can react to events on the WCF client proxy by passing information out to the connected web users.
2) Host SignalR stuff as part of my Windows service. This is already long-running, but I know nada about OWIN and what this would mean for my project. Also the SignalR client will have to connect to a different port than where the web app was served from, I assume.
Any advice on which is the right direction to go in? Keep in mind that in extreme cases, a web user would log in when they get to work in the morning, and only have signalr traffic going back and forth (i.e. no web requests) for a full work day, before logging out. I need them to keep up with realtime events all that time.
Any takers? :)
The benefit of self-hosting as part of your Windows service is that you can integrate the calls to clients directly with your existing code and events. If you host the SignalR server separately, you'd have another layer of communication between your service and the SignalR server.
If you've already decided on using WCF named pipes for that, then it probably won't make a difference whether you self-host or host in IIS (as long as it's on the same machine). The SignalR server itself is always "long-running" in the sense that as long as a client is connected, it will receive updates. It doesn't require manual requests from the user.
In any case, you'll probably need a web server to serve the HTML, scripts and images.
Having clients connected for a day shouldn't be a problem either way, as far as I can see.

vb.net client server - connect to desktop app from website

Tools : VB.net (VS2010), MySQL
I've a client desltop application connecting to my asp.net (vb) website. The desktop app typically sends a request and web app (server) responds to it.
Now, for certain scenarios, I would like website to connect to the client app and sends some data. How do I do it ?
I know client-server app (desktop app to desktop app) but not sure whether this can be done from website to destop app.
Any help is appreciated. Thanks.
You could use SignalR Framework.
From asp.net website : "ASP.NET SignalR is a new library for ASP.NET developers that makes developing real-time web functionality easy. SignalR allows bi-directional communication between server and client. Servers can now push content to connected clients instantly as it becomes available. SignalR supports Web Sockets, and falls back to other compatible techniques for older browsers. SignalR includes APIs for connection management (for instance, connect and disconnect events), grouping connections, and authorization."
Have a look here for documentation and tutorials : http://www.asp.net/signalr

ASP.NET network issue

So i want to to create a web application using asp.net to connect to another application (for example a simple windows form) using sockets. The problem is i'm behind firewall and i don't have the authority to mess with the firewall settings, what other options can i do besides sockets?
My application is fairly simple, the web application will be hosted on the internet and has a "connect" button, when its click it establish connection with the windows form that is on another computer and display the message "Connected" if its connected. All this will be tested behind some kind of corporal firewall. How do i get around this?
The firewall is there specifically to stop this kind of thing.
The bestway around it would be to have the Forms app poll the server for connectivity - this can be made to look near real time by making the server receive the request, then wait until it gets a connect action, or time out after a few minutes and return nothing. Then the forms app would request again.
I think instead of using directly a web application, you should look forward to create a web service to solve both the purposes. You can have its reference in both of them. your Web Form will make a request to connect to the web service instead of application. That will solve both purposes.

Resources