I have an ASP.NET Core site where I implemented a Hub, called NotificationHub:
public interface INotificationHub
{
Task SendNotificationMessage(NotificationMessage message);
}
public class NotificationHub : Hub<INotificationHub>
{
public async Task SendMessage(NotificationMessage message)
{
await Clients.All.SendNotificationMessage(message);
}
}
I have two winforms clients that can successfully connect to the Hub and send/receive messages. I also have a page on my website that can send messages through the HubContext that is injected into my controller.
await _hubContext.Clients.All.SendNotificationMessage(new NotificationMessage { "some message" });
Ideally what I'd like is to send a message to a particular client and not all of the clients. I know that when a client connects I have the Context.ConnectionId available in the OnConnectedAsync method, but I'm not sure how to map that so I can route certain messages only to certain clients from a Controller (or javascript). i.e. A certain activity happens on my web site, I want to notify only one client of that and not the other.