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.
Building the server
SignalR Hub subclass
We now need to create the SignalR Hub. To do this, perform the following steps:
- Add a class to your project to handle the server-side of the chat. We'll call it Chat:
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:
- Now add a Task method to the class to handle the sending of the messages...