Click here to Skip to main content
15,887,862 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to signalr and I want to know if messages can be broadcast only to related records not for users. By that what I mean is suppose I have an master table
masterid
1
2
3
Detail table
DetailID Masterid status
id1 1 pass
id2 1 fail
id3 2 pass
id4 3 pass
id5 1 fail

I am on the webpage and I have masterID 1 record open. I modify the status in detailtable record id1,id2 and I want the data update notification to be sent to my webpage. If I ahve another tab or another user who has open the masterid 2 on thier webpage, signalr must broadcast message only to masterID 1 since that was modified. Masterid2 webpage must not get any broadcast notification. Is this possible in signalr. My webpage is not based on user, or login, it is mostly machine. each machine can have different masterid's open on their browsers.
Is SignalR the right way to go and how to broadcast only to modified clients?

What I have tried:

I tried the BlogDemos sample and
using (var command = new SqlCommand(@"SELECT [MessageID], [Message], [EmptyMessage], [Date] FROM [dbo].[Messages] where messageid=1", connection))
//using (var command = new SqlCommand(@"SELECT [MessageID] FROM [dbo].[Messages]", connection))
{
command.Notification = null;

var dependency = new SqlDependency(command);
dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);

if (connection.State == ConnectionState.Closed)
connection.Open();

var reader = command.ExecuteReader();

while (reader.Read())
{
messages.Add(item: new Messages { MessageID = (int)reader["MessageID"], Message = (string)reader["Message"], EmptyMessage = reader["EmptyMessage"] != DBNull.Value ? (string)reader["EmptyMessage"] : "", MessageDate = Convert.ToDateTime(reader["Date"]) });
}
}
where I specified messageid1, hoping only when record with messageid 1 gets modified broadcast the data, don't broadcast to all clients. broadcast it to only clients who have messageid record open. But it broadcasts even if some other records was modified
Posted
Comments
John C Rayan 1-Mar-16 16:56pm    
SignalR gives you the ability to push data to connected clients. It is up to you how you implement it. I think you push the updates to all clients but in the client side check what record is open and update only if the updated data is matching with the record open. So it is possible.
tp2006 1-Mar-16 17:56pm    
Thanks John! My problem is very similar to this http://forums.asp.net/t/2028264.aspx?Send+data+to+specific+client+from+server The solution proposed there suggests to use userid, mine won't have any userid. In my case there will be million records in the detail table, I don't want the signalr tp push notifications to all the connected clients when some record realted to masterid 1 is modified. Only masterid1 must get notified instead of all clients. Can you give me some example of what you mean please?
Problem a) Don't push notification to all clients isntead push it to only relevant clients.
Problem b) How to identify which masterid got modified? why this notificaiton got triggered. is there a way to find out what changed exactly? and control the notifications tobe pushed only to related master IDs?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900