kami998
kami998

Reputation: 91

Pushing message to multiple clients through SignalR

I am having a Chat app in which i have to push a message to all other users in that conversation, signalr works fine when i push message to all clients over 100 but when i loop over those 100 connections and send message individually then message receives slowly on client side and when I start to push messages faster then my server IIS worker goes to 100% CPU usage and message receiving on client end become more slower,

So help me finding the best way to send messages to specific user from signalr more than 100 users at same time

Upvotes: 1

Views: 1537

Answers (1)

wgraham
wgraham

Reputation: 1393

If it's a chat application, you may want to look into groups in SignalR. Simply create a new group for each "conversation" and join the users to the group.

From the documentation:

public class ContosoChatHub : Hub
{
    public Task JoinRoom(string roomName)
    {
        return Groups.Add(Context.ConnectionId, roomName);
    }

    public Task LeaveRoom(string roomName)
    {
        return Groups.Remove(Context.ConnectionId, roomName);
    }
}

Then you can simply message the group:

Clients.Group(groupName).addChatMessage(name, message);

Upvotes: 4

Related Questions