Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Asp.net core use SignalR to push message process

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how Asp.net core uses SignalR to push messages. I hope you will get something after reading this article. Let's discuss it together.

1), introduction to SignalR

ASP.NET Core SignalR is a library for ASP.NET developers that simplifies the process for developers to add real-time Web functionality to their applications.

Real-time Web functionality refers to the ability for server code to push content to a connected client as soon as it becomes available, rather than having the server wait for the client to request new data.

2). The main uses of SignalR:

Its main uses: it can be used in chat rooms, Web real-time push messages (Real-Push-Message), single-point and multi-point communications, code scanning login, and even combined with other technologies to do video chat and so on.

Candidates for SignalR:

Applications that require high-frequency updates from the server. Examples include games, social networks, voting, auctions, maps, and GPS applications.

Dashboards and monitoring applications. Examples include corporate dashboards, instant sales updates, or travel alerts.

Collaborative applications. Examples of collaborative applications include whiteboard applications and team meeting software.

Applications that require notification. Notifications are required for social networks, email, chat, games, travel alerts and many other applications.

SignalR provides an API for creating a server-to-client SignalR. RPC calls functions on the client side from the server-side .NET Core code. Provides multiple supported platforms, each with its own client SDK. Therefore, the programming language invoked by the RPC call is different.

Here are some of the features of ASP.NET Core SignalR:

Automatically handle connection management.

Send messages to all connected clients at the same time. Like chat rooms.

Send messages to a specific client or group of clients.

It is scaled to handle increasing traffic.

The next key point is to introduce Asp.net core to push messages using SignalR.

Environment:

.net core3.1

one。 Server configuration (Startup)

ConfigureServices

Configure

Second, the custom class inherits Hubpublic class SignalRHub: Hub {private readonly IHubContext _ hubContext = null; public SignalRHub (IHubContext context) {_ hubContext = context;} public override Task OnConnectedAsync () Console.WriteLine ($"{Context.ConnectionId} connected"); return base.OnConnectedAsync () Public void ReadClientMsgMethod (string msg) Console.WriteLine ($"{Context.ConnectionId} client message:" + msg); / all send / public string CallAllClients (string msg) Console.WriteLine ("= all send =") Clients.All.SendAsync ("CallByHub", "all send >" + msg); return MethodInfo.GetCurrentMethod ()? .Name + "; / / send message-send to all connected clients public Task SendMessage (string msg) return _ hubContext.Clients.All.SendAsync (" CallByHub ", msg) } after reading this article, I believe you have some understanding of "how Asp.net core uses SignalR to push messages". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report