I was just reading Hubs at SignalR(https://github.com/SignalR/SignalR) but I couldn't get the clear idea what it is. Is it like groups in chat or something else?
I haven't used it but basically it's a "real time" communication technology for communicating between the client (javascript, silverlight, .NET) and ASP.NET. Currently there are 3 methods for "real time" communication (think chat application): polling, long polling, and HTML5 WebSockets. SignalR adds an abstraction layer and leverages all 3 of these methods depending on browser support and context. Here's an article describing the 3 methods (and how SignalR helps): http://blog.maartenballiauw.be/post/2011/11/29/Techniques-for-real-time-client-server-communication.aspx
And here's an article from Hanselman (and a functioning demo!) on how to use it: http://www.hanselman.com/blog/AsynchronousScalableWebApplicationsWithRealtimePersistentLongrunningConnectionsWithSignalR.aspx
Another: http://jordanwallwork.co.uk/2011/10/signalr/
A Hub is a class used for the communication. In javascript you can use a hub like this:
$(function() {
var myConnection = $.connection.myHub;
$.connection.hub.start();
});
In ASP.NET you do this:
public class Chat : Hub {
public void Distribute(string message) {
Clients.receive(Caller.name, message);
}
}
Both of those snippets were taken from the links referenced above.
You can think of Hubs as Asp.NET MVC controllers for perstistent connections between client (javascript) and server (hub).
Easy way to send different kinds of messages and data between client and server.
Parameters and return values are automatically serialized to and from JSON on the client side.
Hubs have the concept of adding clients to groups so you could with the methods AddToGroup and RemoveFromGroup create chat room functionality. so you can send messages to all clients in a specific group.
I really recommend downloading the code from GitHub and looking through the samples. There is a Chat-sample there with rooms (groups).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With