We'll need to build a server for our chat program, which will contain the methods we want to call from our connected clients. We'll use the SignalR Hubs API, which provides the methods needed for connected clients to communicate with our chat server.
We now need to create the SignalR Hub. To do this, perform the following steps:
This will need to be a subclass of the SignalR Hub
class. Make sure to add the using directive for Micosoft.AspNetCore.SignalR
. Visual Studio's Quick Actions works well for this:
public Task Send(string sender, string message) { return Clients.All.InvokeAsync("UpdateChat", sender, message); }
This method will be called through any of the connected clients and will invoke all connected clients' Send
function, passing through...