A hub is a concept that SignalR uses for clients to come together in a well-known location. From the client side, it is identified as a URL, such as http://<servername>/chat. On the server, it is a class that inherits from Hub and must be registered with the ASP.NET Core pipeline. Here's a simple example of a chat hub:
public class ChatHub : Hub
{
public async Task Send(string message)
{
await this.Clients.All.SendAsync("message", this.Context.User.
Identity.Name, message);
}
}
The Send message is meant to be callable by JavaScript only. This Send method is asynchronous and so we must register this hub in a well-known endpoint, in the Configure method, where we register the endpoints:
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<ChatHub>("chat");
});
You can pick any name you want—you don't need to be restrained by the hub class name.
And you can...