Friday, 19 July 2013

SignalR - The next step

({~. What is SignalR? .~})

SignalR seems to be a nice way to connect the server and client in a website using JavaScript and .Net.
Although this may seem like a quick explanation of a really complicated process, it pretty much sums it up.

||| Probing a little further ...

SignalR essentially creates a live connection between the client and the server through a construct that exists in both locations called a hub.  The client (in your web-app/site) is able to send and receive data from the hub through JavaScript functions and the server is able to send and receive data to the client. Oh, and this can happen in real time depending on your client structure.

In theory, this means that processing, validation, etc, that used to require ajax calls or post-backs can essentially happen on the fly!

\/ We need to go deeper \/

So how does SignalR manage this jiggery pokery.  Well, the Client and Server are connected through a constant socket connection (or through long-polling if your browser is old skool - here's looking at you IE7), that allows calls to be sent to and from the server via the hub.

The hub, as it can be called from both the JavaScript and .Net code, essentially exists both on Client and the Server.  It (the hub) is essentially a singleton .Net class that predefines the functions available and creates itself a JavaScript replicant at runtime.

The JavaScript replicant can then be called by the Client by using JavaScript and the .Net class can be called by any server-side code.

Oh, and did I mention that SignalR can call code from the Client on the Server and vice versa?!
[NOTE: It's probably worth noting now that this feature in SignalR is potentially a huge security risk, so watch out when you're passing around non-encrypted code or don't do it at all!]

There is one more thing that although small is quite exciting, the server can designate which client receives the data it sends.  I'll let you guys stew on that one.

'-. Achievement Unlocked: Boundless Potential .-'

So what can you do with an active connection and a little bit of coding knowhow?  

If you want to be boring, like me, you can start bringing over lost forgotten constructs from the desktop application days, such as a proper progress bar [tutorial will be posted up when I finish writing the thing].

However, if you've got an idea, the sky is the limit.  Create a handy web-based family to-do list [I think I may play around with this idea] or even bring back the real-time multi-computer multi-player game [http://shootr.signalr.net/].  Have fun!

|{ Further Reading }|


No comments:

Post a Comment