Here you can send the ConnectionId to the client and verify it. For example, below is your hub:
[HubName("moveShape")] public class MoveShapeHub : Hub { public void MoveShape(double x, double y) { Clients.shapeMoved(Context.ConnectionId, x, y); } }
At the client level, you can do the following:
var hub = $.connection.moveShape, $shape = $("#shape"), $clientCount = $("#clientCount"), body = window.document.body; $.extend(hub, { shapeMoved: function (cid, x, y) { if ($.connection.hub.id !== cid) { $shape.css({ left: (body.clientWidth - $shape.width()) * x, top: (body.clientHeight - $shape.height()) * y }); } } });
edit
Starting with SignalR 1.0.0-alpha, there is a built-in API for this if you use hubs:
[HubName("moveShape")] public class MoveShapeHub : Hub { public void MoveShape(double x, double y) { Clients.Others.shapeMoved(x, y); } }
This will broadcast the data to everyone except the subscriber.
source share