PowerWebSockets is a high-throughput, cross-platform, full-duplex communication framework in C# that shines at pushing real-time data over a large number of connections between devices, browsers, desktops and servers.
PowerWebSockets offers you full-duplex channels over a single TCP connection using the WebSocket protocol as transport.
Once one side establishes a channel with another side, both sides can send text or binary data to each other whenever they like, with each side being capable of sending and receiving data simultaneously.
Bi-directionality is always available without requiring you to establish a TCP connection from both sides or to poll the other side for new messages.
PowerWebSockets' full-scale use of asynchronous I/O makes it capable of performing massive operations with minimal memory use, enabling you to push millions of messages per second even on moderate hardware.
The resource use of PowerWebSockets scales up and down dynamically depending on the amount of concurrent activities rather than the amount of connections.
Whether you are sending waves of small messages, streaming big data or broadcasting to thousands of subscribers, the adaptive resource management of PowerWebSockets delivers excellent scalability.
To achieve the highest throughput and lowest bandwidth consumption, the compression schemes of PowerWebSockets are specially designed for maximum efficiency with the WebSocket transport while conforming to its "per-message" compression specification.
To improve performance even more, PowerWebSockets incorporates the ultra-fast DEFLATE and LZF4 implementations of DotNetCompression that can further improve scalability with medium-to-large payloads by minimizing the processing overhead required to compress/decompress.
You can set PowerWebSockets to automatically select the compression scheme or you can specify the compression scheme you prefer. Whichever compression scheme you select, it will be transparently negotiated between the communicating sides and your application will remain interoperable with any other WebSocket client or server even if the remote endpoint does not support compression.
Push-to-All is an out-of-the-box mechanism for quickly pushing a single one-way message or a batch of one-way messages to groups of channels connected to a WebSocketService. Sending messages to a large number of channels is as fast as sending them to one channel.
Server applications can broadcast to any clients that are connected to them, client applications can broadcast to any of the servers to which they are connected, and applications acting both as client and as server can broadcast to any side.
When multiple messages are being broadcasted or sent asynchronously one after the other in quick succession, the WebSocketChannel groups them in batches to increase message throughput by sending them together in a single burst. Creating batches is performed without delaying the outbound queue or increasing the use of memory resources.
The Transparent Burst Messaging mechanism of PowerWebSockets takes care of everything automatically, but if you wish you can prepare and send your own batches of messages.
JSON's format simplicity and WebSocket's communication advantages are combined in a powerful communication framework for building real-time Internet applications and services.
PowerWebSockets offers you two APIs:
This section highlights the LiteJM features.
To define your service contract you annotate methods with .NET attributes, similarly to the WCF service contract definition. Any class can act as a LiteJM service. You can use the familiar RPC approach in building your applications.
1 2 3 4 5 6 7 8 9 | [MessagingContract] interface IHelloWorld { [MessageOperation( "Hello" )] string Hello( string message); [MessageOperation( "Goodbye" )] string Goodbye(); } |
You can use all classic types of remote operations including One-Way, Request/Response and Fault messages. In addition to the usual RPC operations, it provides asynchronous streaming and Push-to-All messaging. All operations can be performed both synchronously and asynchronously, except of Push-to-All broadcasts which are always performed asynchronously.
Your application can simultaneously make multiple outstanding requests to the remote endpoint through a single channel.
LiteJM provides asynchronous patterns for calling remote operations, enabling your application to send the next request before receiving responses to previous requests. This allows you to increase the number of concurrent operations without creating extra connections.
One-way and request/response operations can be made in both directions of a connection.
PowerWebSockets does not differentiate between client and server sides as its LiteJM service has the same API and the same capabilities on both ends of a network connection. The only difference is in who connects to whom. Once a connection is established, your side does not matter.
The JSON serialization of LiteJM can optionally preserve the .NET type information, allowing you to use polymorphism when performing a remote operation invocation.
Your PowerWebSockets service can push one-way messages to a large number of channels concurrently by performing only one message serialization, resulting in huge savings of processing and memory resources. Quickly sending a message to thousands of channels is as easy as sending it to one channel.
The ability of PowerWebSockets to associate each connected client or server with a single or to multiple WebSocketService instances enables you to create and manage groups of channels in order to push different messages to different groups. Push-to-All provides you the fundamentals you need to implement your own Publish/Subscribe or Peer-to-Peer architecture.
The Lightweight JSON Messaging of PowerWebSockets is also available as a JSON message encoding binding element for WCF, enabling you to use LiteJM not only in your PWS-to-PWS communications but also in your PWS-to-WCF communications.
A unique feature of LiteJM is its ability to stream an arbitrary amount of binary data as an attachment to a JSON message. This enables you to combine a parameterized JSON request and high-throughput streaming into a single remote operation.
01 02 03 04 05 06 07 08 09 10 11 12 | using ( var fileStream = File.OpenRead( "filename.data" )) { client.RequestWithStream( "upload" , fileStream, "filename.data" ); } ... using ( var fileStream = File.Create( "filename.data" )) { var stream = client.Request<Stream>( "download" , "filename.data" ); stream.CopyTo(fileStream); } |
With PowerWebSockets there is little distinction between clients and servers.
A WebSocketClient initiates a connection, a WebSocketServer accepts the connection, and a WebSocketChannel is established on both sides. The WebSocketChannel represents the full-duplex channel and provides exactly the same functionality at both ends.
The PowerWebSockets service API is independent of whether a connection is outbound or inbound, which means that the same instance of the service can act as a server and as a client at the same time. You can even host the same WebSocketService implementation on both the server and the client side.
PowerWebSockets allows you to transfer messages of arbitrary size, hiding all the complexity of message fragmentation and giving you maximum ease of use.
The streaming API of PowerWebSockets is very straight forward, representing each inbound or outbound message as a .NET stream. No buffering of the message or its frames is required, allowing you to transfer messages of unlimited size and to accept frames up to 2^64 bytes long while consuming only a few KB of memory.
Any inbound message can be received either buffered or streamed, irrespective of whether the remote side sent it as a single frame or in a stream of fragments.
Activating TLS is as easy as switching the URI scheme from "ws:" to "wss:" and providing the server's X.509 certificate.
You can use TLS authentication with X.509 certificates to perform server authentication or mutual authentication of both sides. In addition to TLS authentication, you can also perform client authentication using HTTP basic authentication with usernames and passwords.
PowerWebSockets provides TLS security on all supported platforms -- even on platforms on which .NET does not provide TLS streams, including .NET Compact Framework, Windows Phone and Silverlight.
The Internet of Things is all about enabling a diverse range of computing devices to communicate over the Internet so that they can provide and consume data and services.
Whether you are writing client-side or server-side software for the IoT, PowerWebSockets is a complete toolkit that includes everything you need: a standard bi-directional prototol, mutual TLS security, DEFLATE and LZF4 compression, Lightweight JSON Messaging, big data streaming, and the scalability required to interconnect a large number of devices.
Want to create servers running on iOS, Android and Compact Framework devices? Now you can have servers everywhere!
PowerWebSockets-enabled devices are capable not only of establishing full-duplex client connections, but also of accepting connections and providing services to other WebSocket clients.
WebSocket is a new protocol that represents the next generation of communications across the Web. It enables the creation of event-driven applications that send and receive data at will without polling or page refreshing.
WebSocket is part of HTML5, with the IETF standardizing the WebSocket protocol and the W3C standardizing the WebSocket API.
Although WebSocket was initially intended to be used mostly by browser clients, at the IETF its specification was improved to become a universal protocol for efficient, real-time, firewall-friendly communications over the Internet for connecting any type of client to any type of server.
Noemax has been an active participant and contributor in the Hypertext-Bidirectional (HyBi) working group of the IETF that defined the WebSocket protocol (RFC 6455) and its compression extension.
At Noemax we have a large set of unit, performance and interoperability tests for PowerWebSockets that are run regularly, but we have also tested specification conformance and implementation robustness using the Autobahn|Testsuite for the WebSocket protocol.
Did you know that Chrome, Firefox, Internet Explorer, Safari and Opera are WebSocket-enabled and can connect to your PowerWebSockets servers?
With PowerWebSockets you can accept connections from any 3rd party client that supports the WebSocket protocol, including browsers.
And with PowerWebSockets you can also connect to any 3rd party server that supports the WebSocket protocol, including Apache, IIS and Nginx.
Since PowerWebSockets channels may be long-lived, you can use the internal keep-alive mechanism to send pings in order to ensure that your persistent connection remains alive and to verify that the remote endpoint is still responsive. Pongs are returned automatically.
The PowerWebSockets keep-alive mechanism offers multiple modes of exchanging the standard heartbeat control messages, giving you detailed control and enabling you to configure it depending on the type of network infrastructure and the desired level of network error detection.
PowerWebSockets provides integrated tracing support that allows you to monitor its activity. A PowerWebSockets application can even be traced remotely by another PowerWebSockets application.
You can configure the TraceSource with any type of trace listeners and then assign the TraceSource property of the WebSocketClient, WebSocketServer, WebSocketEndpoint or WebSocketService objects to the specified trace source in order to log events associated with the object being traced.
Looking for a substitute for the aging system-provided net.tcp transport?
Feeling restricted by the system-provided WebSocket implementation whose client side is available only on .NET Framework 4.5+ and its server side only on Windows Server 2012+?
PowerWebSockets includes two binding elements for Windows Communication Foundation clients and severs:
The WebSocket transport binding element of PowerWebSockets is available on all platforms supported by PowerWebSockets including all .NET versions from 3.5 onwards, all Xamarin platforms, Windows Phone, Silverlight and Mono -- practically, almost everywhere WCF is available.
Performance features such as full-scale asynchronous design, adaptive resource management, transparent burst messaging and ultra-fast transport compression are also available in the WebSocket transport binding element of PowerWebSockets.
The WebSocket transport binding element of PowerWebSockets supports the "per-message" compression specification and provides two compression extensions, DEFLATE as per the specification and LZF4 for minimal processing overhead.
The JSON message encoding binding element of PowerWebSockets enables any WCF client or server to communicate using LiteJM with any other WCF or PWS client or server that also uses LiteJM and the same transport.
This message encoding can be used with any WCF transport, but it is recommended to be used primarily with:
LiteJM features such as duplexity and concurrency work only with WCF transports that support them.
With PWS you can create | With PWS you can create | |
---|---|---|
CLIENTS |
SERVERS |
|
.NET Framework 4, 4.5 and 4.6 | ||
.NET Framework 3.5 | ||
.NET Compact Framework 3.5 | ||
Xamarin.iOS | ||
Xamarin.Android | ||
Xamarin.Mac | ||
Windows Phone Silverlight 8 and 8.1 | ||
Windows Phone 7.1 | ||
Silverlight 5 | ||
Mono |