![]() We will modify our JavaScript client first. And now we need to get our clients to call it. So, as you can see, this method is identical to BroadcastMessage we had previously, except for one little detail. ![]() Open LearningHub.cs file in your SignalRServer project and add the following method to the class: public async Task SendToOthers(string message)Īwait (message) ![]() In SignalR, this can be achieved by using Clients.Others instead of Clients.All. What if you want to exclude the client that has sent the message from the list of its recipients? But this way of broadcasting a message has its limitations. This was achieved by making the call on Clients.All property in the server-side hub. In the previous article, we have already broadcasted SignalR messages to all connected clients. The complete code samples from this article are available from the following location in the GitHub repo, which has separate folders corresponding to individual parts of the article: the-complete-guide/tree/main/Chapter-04/Part-03/LearningSignalR If you have skipped the previous chapter, you can access the complete code from the following location in the GitHub repository: A suitable IDE or code editor (Visual Studio, JetBrains Rider or VS Code)Īlso, since we are continuing to build on top of the application that we have developed in the previous article, we need the code that we have written previously.A machine with either Windows, Mac OS or Linux operating system.To follow the examples from this article, you will need the following: So, this article covers the following topics:īy the end of this article, you will have learned how to be selective on which clients you want to send messages to from SignalR hub. So you can exclude it from the list of recipients. ![]() After all, the client already knows what the message is. And this is what we will talk about today.īut even if you broadcast messages to all clients, you don’t necessary have to include the client that the message has originated from. You can also group clients together and send messages to specific groups of clients. The hub allows you to send messages to individual clients. But this is far from being the only way you can use SignalR. SignalR hub can broadcast a message to all connected clients. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |