- •Contents at a Glance
- •Introduction
- •Who should read this book
- •Assumptions
- •Who should not read this book
- •Organization of this book
- •Finding your best starting point in this book
- •Conventions and features in this book
- •System requirements
- •Code samples
- •Notes on the version
- •Installing the code samples
- •Using the code samples
- •Acknowledgments
- •Errata & book support
- •We want to hear from you
- •Stay in touch
- •HTTP operations
- •Polling: The answer?
- •Push: The server takes the initiative
- •WebSockets
- •Server-Sent Events (API Event Source)
- •Push today
- •The world needs more than just push
- •What does SignalR offer?
- •Two levels of abstraction
- •Supported platforms
- •OWIN and Katana: The new kids on the block
- •Installing SignalR
- •Implementation on the server side
- •Mapping and configuring persistent connections
- •Events of a persistent connection
- •Sending messages to clients
- •Asynchronous event processing
- •Connection groups
- •The OWIN startup class
- •Implementation on the client side
- •Initiating the connection by using the JavaScript client
- •Support for older browsers
- •Support for cross-domain connections
- •Sending messages
- •Receiving messages
- •Sending additional information to the server
- •Other events available at the client
- •Transport negotiation
- •Adjusting SignalR configuration parameters
- •Complete example: Tracking visitors
- •Project creation and setup
- •Implementation on the client side
- •Implementation on the server side
- •Server implementation
- •Hub registration and configuration
- •Creating hubs
- •Receiving messages
- •Sending messages to clients
- •Sending messages to specific users
- •State maintenance
- •Accessing information about the request context
- •Notification of connections and disconnections
- •Managing groups
- •Maintaining state at the server
- •Client implementation
- •JavaScript clients
- •Generating the proxy
- •Manual generation of JavaScript proxies
- •Establishing the connection
- •Sending messages to the server
- •Sending additional information
- •Receiving messages sent from the server
- •Logging
- •State maintenance
- •Implementing the client without a proxy
- •Complete example: Shared drawing board
- •Project creation and setup
- •Implementation on the client side
- •Implementation on the server side
- •Access from other threads
- •External access using persistent connections
- •Complete example: Monitoring connections at the server
- •Project creation and setup
- •Implementing the website
- •System for tracing requests (server side)
- •System for tracing requests (client side)
- •External access using hubs
- •Complete example: Progress bar
- •Project creation and setup
- •Implementation on the client side
- •Implementation on the server side
- •Multiplatform SignalR servers
- •SignalR hosting in non-web applications
- •SignalR hosting in platforms other than Windows
- •Multiplatform SignalR clients
- •Accessing services from .NET non-web clients
- •Consumption of services from other platforms
- •Growing pains
- •Scalability in SignalR
- •Scaling on backplanes
- •Windows Azure Service Bus
- •SQL Server
- •Redis
- •Custom backplanes
- •Improving performance in SignalR services
- •Server configuration
- •Monitoring performance
- •Authorization in SignalR
- •Access control in persistent connections
- •Access control in hubs
- •Client authentication
- •An extensible framework
- •Dependency Injection
- •Manual dependency injection
- •Releasing dependencies
- •Inversion of Control containers
- •Unit testing with SignalR
- •Unit testing of hubs
- •Unit testing persistent connections
- •Intercepting messages in hubs
- •Integration with other frameworks
- •Knockout
- •AngularJS
- •Index
- •About the author
FIGURE 7-4 Sending parameters to the service.
SignalR hosting in platforms other than Windows
It is a good idea to note that all the infrastructure on which we are building our services is based on open standards, in many cases with implementations distributed under very permissive licenses, which opens the door to the possibility of executing the applications on platforms other than Windows.
If we add this to the availability of multiplatform implementations of the .NET platform, it is possible to take SignalR applications to other popular operating systems where it would a priori seem impossible, such as Linux, BSD, or Mac OS X.
The Mono1 project was begun in 2001 by Ximian, a company started by Miguel de Icaza for the purpose of creating a multiplatform and open source implementation of Microsoft’s .NET Framework, based on the ECMA standard of C# and Common Language Runtime (CLR). Currently, Mono provides support, even at binary level, for a large number of features offered by version 4.5 of the .NET Framework, although there is obviously a slight delay in their implementation when it comes to the new features that continue to appear in the new versions of the .NET Framework. In fact, to access the most recent features, it is recommended that you download the source code from its repository at
1 Official website of the Mono project: http://www.mono-project.com
126 Chapter 7 Real-time multiplatform applications
www.it-ebooks.info
GitHub2 and that you generate the specific binaries for the local computer by following the instructions provided.
At the time of writing, even the SignalR framework itself can be completely compiled on Mono.
The Readme.md file that we find on the main page of the repository in GitHub provides instructions to obtain a copy of the source code and compile it using the command line as shown in Figure 7-5.
FIGURE 7-5 SignalR compilation from the Linux command line with Mono.
2 Mono Project repository at GitHub: http://github.com/mono |
|
Real-time multiplatform applications Chapter 7 |
127 |
www.it-ebooks.info
It is also possible to debug or make modifications to SignalR by using MonoDevelop3, a multiplatform integrated development environment also created and distributed under the same open source premises as the Mono ecosystem. For this, in the SignalR source code, a solution file is included
(Microsoft.AspNet.Signalr.Mono.Sln), which we can open from this IDE to modify or compile the project, as shown in Figure 7-6. Obviously, projects that are very specific to the Microsoft platform, such as scalability adapters for SQL Server or Windows Azure, are not found in this solution.
FIGURE 7-6 Compiling SignalR from MonoDevelop.
The SignalR self-hosting server components can be successfully executed on Mono (see
Figure 7-7), but the same does not happen with the server based on ASP.NET/IIS, because the implementation of the latest version of the platform is not yet fully supported. Hopefully, this will change in the near future.
3 Official website of the MonoDevelop project: http://monodevelop.com
128 Chapter 7 Real-time multiplatform applications
www.it-ebooks.info