This post outlines the some of the improvements in new version of SignalR that included in Visual Studio 2013. In this version 2 issues related performance, stability and API usage are addressed. What is SignalR? SignalR enables you to do the real time browser-server communication that uses the best technology client and server support.
SignalR API improvements
One of the first features that you can find is ability to send the same message or invoke the same method on multiple clients at same time using Groups or Client Ids.
The above method can be called from client side code which is taking a string array that represents the names of the groups. Now you have the Groups method on Clients and pass in groups list. In earlier version of SignalR the same can be achieved by looping over string array and invoke the same method essentially multiple times one time for each group.
Now you also have the ability to send the message directly to the user. In SignalR 1 this was handled on OnConnected method by getting the connection id and username from userinstance from somewhere in your application. This approach is still can be used.
Other areas where you can find the improvements are error handling, In SignalR by default if you throw an error inside the Hub invocation those errors donâ€™t way back to the client. You will get a generic error message to the client. Now you have a new exception type HubException. You can throw this exception providing a user message and any other arbitrary data that is useful for client.
The client side invocation looks as follows
Now if you debug this code then you can easily understand where the error is coming from, notice the source HubException.
Now it is easy to unit test the Hub methods on server side code. A new Startup class is introduced in SignalR2
The advantage of above Startup class is it is not directly tied up with ASP.NET so if you want to host the SignalR connection and Hubs in different process on custom server commonly known as self-hosting then you can do that now, all you need to do is bring the supported self-hosting Nuget packages and install in your application as shown below