HTML5 WebSockets Client for .NET
So, I found that amazing thing called HTML5 WebSockets, new API. That is still in DRAFT version, but quite well supported. Full-duplex bi-directional communication. I know how to use it via JavaScript, there is APIs. But if I want to use a WebSocket cl开发者_高级运维ient within my C#/.NET application, how to do that?
For example JavaScript: http://bohuco.net/blog/2010/07/html5-websockets-example/
Are there are any special client libraries for WebSockets in .NET?
sir SuperWebSocket include a WebSocket server implementation and a WebSocket client implementation. SuperWebSocket's project page
I've recently done some research into this whilst building a .NET and Silverlight client library for Pusher. I found the following WebSocket client libraries and projects:
- Microsoft WebSocket client prototype
- SuperWebSocket note: there is a client in there, it's just difficult to find
- WebSocket-Sharp
- Anaida
For the moment the Microsoft implementation is probably the easiest to use and it also has a Silverlight library. SuperWebSockets has a Silverlight project in the source but not in the latest drop.
Starting from .NET 4.5, WebSocket clients are supported via System.Net.WebSockets.ClientWebSocket
You can browse or download this sample C# app from MSDN Code website: http://code.msdn.microsoft.com/WebSockets-middle-tier-5b2972ce/sourcecode.
To the down-voters of the question, the sample is mainly focused on connecting to WebSocket services, which is another significant use-case for a network-centric C# application.
I haven´t tried the Microsoft implementation, but I think Xsockets has the fastest setup time (nuget package). Under 3 min from start to running a complete socketserver + client (demo chat application). Youtube demo
It has fallback to Silverlight and flash for older browsers.
You could use http://www.nuget.org/packages/Microsoft.AspNet.SignalR/ or http://www.asp.net/signalr
ASP.NET SignalR is a new library for ASP.NET developers that makes developing real-time web functionality easy. SignalR allows bi-directional communication between server and side. Servers can now push content to connected cliently instantly as it becomes available. SignalR supports Web Sockets, and falls back to other compatible techniques for older browsers. SignalR includes APIs for connection management (for instance, connect and disconnect events), grouping connections, and authorization.
A friend an I just released a very lightweight, lean, scalable C# websocket server: https://github.com/Olivine-Labs/Alchemy-Websockets
We built it to use in our online game, so our top concern was the quick and efficient handling of tons of connections. It's, from my research, the most efficient out there. And, as a bonus, it supports flash websockets as a fallback for users without websocket-enabled browsers.
If you're looking for a high performance enterprise WebSocket server, take a look at Kaazing. Kaazing has complete support for .NET including Xamarin.
Here is a step-by-step tutorial for AMQP: Checklist: Build Microsoft .NET AMQP Clients.
[Disclosure: I work for Kaazing.]
Yes, you will need an intermediary server which supports the WebSocket protocol. This server could be written in any language including .NET. Here's one for .NET but it really could be any language. As far as your site is concerned it could be ASP.NET and the client part in javascript which will talk to the WebSocket server.
I'm deploying XSockets.net. The framework works quite good, it is being maintained, the developers offer paid support but for normal issues they are also quite active here in SO and they help a lot.
They offer a .net API for implementing the sockets and also a javascript API for the client.
As a summary, I can recommend it.
You have a few choices
- Roll your own - the spec is fairly simple
- Use someone else's experimental version, such as this one C# Web socket server
- Look into the MS WCF approach
精彩评论