To respond to a specific client with connectionId you can do something like this:
var connectionId = Context.ConnectionId;
Clients.Client(connectionId).someMethod(resultValue);
Or to respond only to the caller:
Clients.Caller.someMethod(resultValue);
These calls are made from within public methods in your hub class, and do the same.
EDIT:
It looks like the connection.start() should be expanded a bit. You do not need to handle the connectionId, if the server are going to return data or callback to an event at the caller. This will be done by the server, and handled by the methods posted above.
Try changing the connection.start()
line to something like this:
connection.start().done(function() {
$('#someButton').click(function () {
var param1 = $('#someField').val();
var param2 = $('#someField2').val();
this.proxy.invoke('myHubMethod', param1, param2, paramN);
});
});
Do the neccessary changes to apply this to yout implementation. This code is based on the one you'll find in the documentation. Since it looks like you don't use the generated proxy, we use the invoke
method on the proxy to tell which method, and which parameters we are going to send. This also wires up an event to a button with id=someButton
, which will fire the myHubMethod
on the hub when clicked.
The alternative would be something like (with generated proxy):
this.proxy.server.myHubMethod(param1, param2, paramN);
You should take a look on the ASP.NET SignalR Hubs API Guide - JavaScript Client