I am planning to create a chat application, and I\'ve read that SignalR is one of the best technologies to apply.
I\'ve seen examples of it, but they only have a sin
You don't have to open multiple connections, just one, but to use Group
:
public class MyHub : Hub, IDisconnect
{
public Task Join()
{
return Groups.Add(Context.ConnectionId, "foo");
}
public Task Send(string message)
{
return Clients["foo"].addMessage(message);
}
public Task Disconnect()
{
return Clients["foo"].leave(Context.ConnectionId);
}
}
One group means one room, so every time one user joins one room, you just add that user to the group of that room, and when you want to broadcast message, just send the message to the clients in the group.
More details: https://github.com/SignalR/SignalR/wiki/Hubs