Intro to SignalR in C# Part 2 - Beyond Chat Applications
HTML-код
- Опубликовано: 27 июл 2024
- SignalR is for more than just chat applications. In our last video, we saw the standard demo for SignalR, where we could connect multiple clients to a chat hub. In this video, we are going to extend that demo by adding a second hub. This one will trigger the counter on the Blazor page from our WPF project.
Full Training Courses: IAmTimCorey.com
Source Code: leadmagnets.app/?Resource=Int...
Mailing List: signup.iamtimcorey.com/
Tim, thank you for demystifying SignalR. Great tutorials as always. Much appreciated.
You are welcome.
Thanks for this. I thought part 2 would take longer but you pulled it off so quickly. Going to allocate some time to absorb your knowledge fully.
You are welcome.
Another great video. Thanks Tim. It takes so much time and effort to create this type of tutorial. Thanks again.
You are welcome.
Thanks Tim! Looking forward to parts 3, 4, 5 & 6... or better yet a published course on your site for more of this. These first two parts were definitely a great ice-breaker, at least for me, since I hadn't yet explored SignalR. Sometimes you have to turn off the learning, in favor of getting stuff done. Nevertheless, your videos always save me time compared with self-learning, so when I saw the notification for SignalR Part 1, I couldn't resist. So thanks again!
Thank you! And thanks for the suggestion.
we need mroe for signalR. Maybe u may say about how to store messages so every new client can connect and see messages when he was not avilable. Moreover same scenario just when particural user send to any other specific user like in the chat app like Whatsup.
How to send to specific clients would be great.
Thank You.. It is just Iftar gift for me.. I can't watch this right now... I will watch after Ramadan Iftaar.. Thank You Tim Corey ❣❣
You are welcome.
What a great tutorial. Thank you so much. I will love to see the advance part where one can send message to specific client
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
Very nice work!!! As always great!
Thanks!
Thanks for the help this video provided! I'd love to see a video about what security, authentication, authorization, etc. is available in SignalR, and how to implement them.
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
Hi Tim !You are doing an excellent job , but in this video I was waiting to see how to send data to specific users not to everyone equally. hope to make a video for this. Thanks !!
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
Thanks Tim.
Blazor is powerful.
You are welcome.
@@IAmTimCorey
Using Signal R how to display a driver locations on the map like uber ?
Really great video, I've learned alot about signalR but I would like to know how to broadcast to only a certain amount of people like admins recieving notifications about something etc.
Track them when signal r connect, with a dictionary forexample user to connectio. Id, user roles to connection ids and so fourth. When you want to prodcast to admin get all admin "whom are connected" and send message to thwm
You can add the admins to a group and send whatever message to them.
Or track admins with a database or dictionary
I agree: that would be a great Part 3.
What are you looking for in part 3?
@@IAmTimCorey Sorry, I was meaning to put that in reply to @Simnico99's (ruclips.net/channel/UCQRVFuD0t68EyxV8Hl0Ypfg) comment asking about "how to broadcast to only a certain amount of people like admins receiving notifications about something etc." It was not meant to be a top-level comment. ☺️
thank you for the 2 part series, good intro to Blazor and SinglR. The only issues i had was an outdated Visual Studio and the restrictions my organization placed on my laptop where I couldn't run the WPF App. Even though I have admin rights it keeps saying "Access Denied".
You are welcome.
Great presentation. Thanks! Would love to see signalR authentication covered at the same level. Subscribing!
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
Hey Tim, Thank you for this tutorial again!
Can we use SignalR for trading applications?
Yes you can!
Hey, Tim! Would be great to understand how to send the messages to specific clients. Imagine whispers or private messages on chat apps.
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
how do we save this information? Let's say a user closes its client, and open it back up, How can the user see where they last left off from?
Thank you for a short and clear work. If I need a web app on the client side, can I create a ASP razor page app as client to be run on non windows device?
Yes, you can. You can also create a JavaScript client (no C#) or clients in other languages.
Hi, Tim.
I would like to avoid "magic strings" in the method names. What's the best practice? Using interfaces, for instance?
Probably just string constants, maybe in a shared library so that other projects can use the same constants. It won't solve all of the naming issues, though, since some are method names that then correspond to strings. For that, you might try "nameof()", but that might get hacky.
Great as usual. I've just one request if you can explain the SignalR + Newtonsoft.Json or MessagePack protocols. Thanks
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
Hi Tim, thank you for the video. I need to know more about where to host my application using SignalR with maybe 100 users connected at the same time and chatting and playing together. And also some information about Azure SignalR pricing. Thanks
You can host your app anywhere with just 100 concurrent connections. That's not really a big deal. 10,000 would be where I would start looking for other solutions. However, if you want to offload your SignalR connections anyway, you could do so for $50/month if you hosted on East US: azure.com/e/62513f4b4772453ab8a051795e515784
Note that this plan covers 1,000 concurrent connections and gives you 1,000,000 messages for free before it starts charging you for additional messages.
thank you tim for your awesome educational content. i have a question about writing tests for signalR. is there a recommending way to write tests rather than just mocking in unit tests? for example is it a good idea to bring up all dependencies with docker and test if chatHub is working properly?
im asking this because all the time my frontend says that something on serverSide is not working properly and then i should test my release on stage server by bringing up a console app(using Microsoft.AspNetCore.SignalR.Client) which acts as the client and test the stage server like that.
Unit tests test just one unit of work. They don't test the interconnected system. It sounds like you are wondering about end-to-end testing. That can be a good thing, although it is tricky to get right, expensive to build, and it will be constantly changing. That means that you don't do it very often and you don't do many of them. The way to do it would probably be to spin up a full setup in Docker or something else where you can reset the environment easily.
However, in this specific case, it sounds more like you are having a problem in production and need to track down what is going wrong. In that case, good logging is a better option. That way, you can read through the logs and identify what went wrong.
Waiting for part three😁
There isn't a part 3 scheduled. What would you like to see in a part 3?
Hi, nice video, thanks. One important feature that was not mentioned is the capability to send menssages to a specific user, even if the user is not logged in. Like send a message for a specific visitor session on a website...
I mentioned it but I did not show it. That's a more complicated process that would have been too long to add to a video. It would need to be its own video.
@@IAmTimCorey Hi, thanks so much for answering. Actualy I've already done sending individual messages... had to find out how to do it on my own, but it would be a very good video to make. A whole series on SignalR. It's a very good tool with so many applications...
Great demo of SignalR - I have done Tim's Blazor Server course which also demos SQL connections. I just wondered whether Tim could demo using SignalR to stream data from the data base. Also I'm interested in using SignalR to receive location data from a mobile phone and the display this real time on a google map - any thoughts on this?
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
please more videos about signal r.
and what other compression is able out of the box and which one best??
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
Would love to see a video on broadcasting changes from and SQL Server database to connected clients.
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
A third part would be nice regarding to use signalR with javascript in the client.
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
Hi Tim, is there any difference between InvokeAsync(StateHasChanged) and StateHasChange()
InvokeAsync is needed when you know that the code might be executed on a background thread and the code modifies components/objects owned by the UI thread. Without InvokeAsync you will run into exceptions being thrown if you try to run StateHasChanged from a thread other than the main UI thread.
Hi Tim, Thanks for these SignalR videos. Your sample works fine when I run it on one machine with the server app running from Visual Studio. But I get a 'No connection could be made because the target machine actively refused it. (localhost:7181)' when I run the WPF app on another machine on same wifi. Have you got a tip?
Running multiple devices on the same wifi network does not mean you can connect to other devices localhost. Each device has their own localhost, you can think of localhost as the current device itself. So your WPF application is trying to connect to a server running on that same specific device, but fails, because there is no server running on the WPF machine's localhost.
The best thing to do would be to publish your SignalR server to a web server. They are designed to be reachable by other machines on the network, or even across the Internet. You can set up your local machine to be a web server. This video will show you how: ruclips.net/video/PPaqVyBkwMk/видео.html Just note that you will then need to make sure your local machine's firewall permits access on the correct ports, plus you will need to add a SSL certificate on your local machine that the other machines trust, plus you will need to access your machine remotely using your machine's IP address. As @Diego pointed out, the word "localhost" represents the machine you are on. That doesn't work when you want to access a remote machine. In that case, you would access it by the IP address.
Great video! Question: How do I get Vs2022 to insert Pattern: Method: Page: etc ? @IAmTimCorey
Thanks for the video. I added .MAUI project in worked well in windows application but Android real device and emulator didn't.
adb reverse tcp:7181 tcp:7181
Used above to get access localhost:7181 but got following error message "java.security.cert.CertPathValidatorException: Trust anchor for certification path not found"
Do you might know what to do next? Do I need self signed certificate? Override some security classes?? Change some security options? Kind of stuck. Self signed certificate sounds next to try.
It sounds like your emulator does not trust the certificate. Self-signing won't change that (you already have a self-signed certificate for your API). What you need to do is trust that certificate. That would be my guess.
Thanks
You are welcome.
Hi Tim, can you make a video for Signal R connection with angular?
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
Let's imagine that I have Web API and additionaly SignalR for notifications.
- Is there a way to share authentication data between those 2 server side services ?,
- Do I need to invoke SignalR method from client side (frontend: update something via Web API method, than send notification) or I can do it from backend (frontend: update something via Web API method (for ex. ApproveFollower), backend: inside Web API method ApproveFollower, send a notfication to the follower user via SignalR) ?
Yes, they can share authentication. Yes, you can alert the clients from the server. You can't establish a connection from the server to the client, though. The client needs to be the one to establish a connection.
A single NIC is limited to 65536 simultaneous connections IIRC. What's available for web sockets would be slightly less.
I think this is a confusion on network ports vs network connections. You can (and do) have multiple connections over one port. Web servers, for instance, usually use port 443 for serving a website, yet they can have more than one visitor at a time. A network card has roughly 65,000 ports that can be used simultaneously. For instance, on the same server you can be using FTP on port 21. With SignalR, you are using the web communication channel (usually port 443) for all communication. Inside of it, you can have multiple WebSocket connections at once. By default, IIS limits you to 5,000 connections per CPU, but you can increase that dramatically. The bottleneck, though, will be the server's ability to keep track of all of those links. Even the bandwidth won't really be a problem, since you usually send very small packets across the wire. 100,000 clients sending 1kb packets would only result in a 100MBps transfer rate. It is a rare business that cannot sustain that much traffic to their commercial site. That's why the bigger problem is the computer driving all of those changes at once. It will have a lot of bottlenecks trying to talk to 100,000 clients at once.
@@IAmTimCorey You're right of course, excuse the brain fart! Thanks for the videos! I tried out gRPC per another of your videos to make a client/server app (both in winforms) so I could send keystrokes I hooked from a VMware guest to the host so my multimedia keys would function on my host. It took forever to figure that out because when your mouse is hovering over a VM window, VMware will hijack the keydown/up messages you want to send via SendMessage and send those messages back to the guest, creating an endless loop!. I finally figured that out, but ended up ditching gRPC and using SignalR because I got stuck on an issue with gRPC not working in Win7 VMs due to an http/ssl version issue I think. I figured I'd give SignalR a shot to learn a bit about it. I don't think I'll ever try gRPC again just because I didn't like the gotchas you warned us about, because they got me even after your warning.
Could you send the github link for this sample?
I don’t have a GitHub link. There is a link in the description to download the source.
Part 3, UI dashboard please?
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
Otherthan WPF, Can this work with winform project type as a client?
Sure. It can work with almost any client.
@@IAmTimCorey Thanks
How to publish SignalR on Heroku?
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
Tim, do you have any resources on working with groups and how to send messages to specific groups of users and connection pools? I have it working somewhat, but the amount of messages being dropped is astronomically high. Approximately half or more messages are dropped so I think I may be doing something incorrectly.
I don't have an example of that yet, sorry.
@@IAmTimCorey Okay. I have been fighting with setting up Azure SignalR via a deployed API and connecting to receive messages via a JavaScript client. Talk about a headache.