ASP.NET Core+Vue3 implements SignalR communication
ASP.NET Core+Vue3 implements SignalR communication Starting from ASP.NET Core version 3.0, SignalR’s Hub has been integrated into the ASP.NET Core framework. Therefore, in later versions of ASP.NET Core, it is no longer necessary to reference the Microsoft.AspNetCore.SignalR package separately to use the Hub. Create a class in the project that inherits Hub, The first is to write a CreateConnection method ConnectionId is the unique identifier of the client connection identified in SignalR, Associate userId with ConnectionId, so that you can send messages to a specific user or users. SendMessageToUser method is used to send messages to specific users. It accepts two parameters: userId represents the user ID to be used to receive messages, and message represents the content of the message to be sent. The main function of this method is to obtain the ConnectionId associated with the userId from the memory cache (IMemoryCache), then use the Clients.Client(connectionId.ToString()) method to find the corresponding client connection, and send the message to this user. This way, users can receive specific messages. public class MyHub : Hub { private readonly IMemoryCache memoryCache; public MyHub(IMemoryCache memoryCache) { this.memoryCache = memoryCache; } public void CreateConnection(int userId) { //Associate the user ID with the ConnectionId memoryCache.Set(userId,…