I heard SignalR is a good messaging library. I got some code for SignalR but I am not able to understand how it works.
JS
var hooking;
$(function() {
hooking = $.connection.hooking;
hooking.removeLead = function(ref) {
$("lead" + ref).remove();
};
$.connection.hub.start();
});
C#
// Hooking.cs (placed in application root)
public class Hooking : Hub
{
public void Submit(string jsonString)
{
var serializer = new JavaScriptSerializer();
var json = serializer.Deserialize<HookingLeadResult>(jsonString);
Clients.removeLead(json.Ref); // Remove lead from client hooking windows
// update lead gen
}
}
I have questions about the above code.
- What does
hookingmean ins$.connection.hooking; - Where is
removeLeadinhooking.removeLead - What will this do
$.connection.hub.start();? What does it start? Which method it will invoke at the server side? - Who & how
Submitmethod will be called at the server side? how to pass data from client side to server side. If possible please give me a url for good start for SignalR library.
The Javascript function
hooking.removeLeadwill be invoked whenever you callClients.removeLead(). All the bindings are done dynamically, between Javascript to C# and between C# and Javascript.$.connection.hub.start()is actually the connect function. It will connect your client to the server. No messages can be sent or received until you do. Thestartfunction allows you to define a callback to be called when it’s done connecting.The
Submitmethod at the server will be called whenever you do ahooking.submit(json)call on your client. For instance, as a result of the user filling in some form and clicking a button.I recommend starting with the SignalR official wiki: http://www.asp.net/signalr