Out of many uses of real time communication using SignalR, chat is one of the important features. Here, I will try to explain the difference between two methods in SignalR to send group messages.
Using the Code
SignalR has two methods:
(In both methods,
receiveMessage(msgFrom, msg) is a client side method to be called from SignalR Hub server.)
Both methods are useful in group message broadcast. But there is an important difference between these two methods.
...broadcasts the message to all connected users of hub. To send message to limited users, exclude those users, is the option given.
string Exceptional = new string;
Exceptional = connection_id;
To add number of connection ids to an array is a hectic and time consuming work. Hence it is better to use Group messaging in a signalR.
It is the right method to broadcast messages to users connected to group. Here also, the option to add, exceptional is available to exclude some users from receiving messages.
...to add connection id of incoming user to group.
For private chat, rather than excluding all other users than receiver one, simply send the message only to the particular user.
touserid is the connection id of user who is going to receive the message.
Please find my article, “SignalR with ASP.NET – One-to-one and Group Chat with Database Record Maintained at Server” for demo application of the same along with explanation.