We are working on a social network application and are going to implement couple of new features. 1. Tracking online users 2. Chat (one to one chat and later group chat)
I am using SignalR as a kind-of chat architecture too. Works perfectly an our single IIS server setup. For scalability check out: Sclaing-out-SignalR
If you are using Hubs, you can solve the "I am online" problem by querying the connected clients like this
var clients = Hub.GetClients<Type of your hub here>();
and request the UserID from each client. If there is a loss of any connection you have to find the in DB online users, that are no more clients of the hub.
OR
Another approach is to set the user online as a first message from user to hub. "Hi I am there". And use this solution
public class MyHub : Hub, IDisconnect
{
public Task Disconnect()
{
// Query the database to find the user by it's client id.
var user = db.Users.Where(u => u.ConnectionId == Context.ConnectionId);
return Clients.disconnected(user.Name);
}
}
To handle the disconnect event.
Hope I could give you some ideas.
SignalR is better than polling because of the network traffic involved with db connections. Also, think about what version of signalR you'll be using with your MVC project as the latest version of signalR only supports .net 4.5.
As for the number of connections, it depends on how much memory you have and how many connections you have configured in IIS. You can easily handle 1000+ on a decent rig.
As with Tom's answer, you can intercept events to hubs or lower signalR interfaces to get counts, disconnect and connect events.