49

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 client 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?

3
  • 4
    I wonder why this question was downvoted. It seems like a perfectly valid question to me. It's just that the OP doesn't explain quite well whether he is looking for implementing a WebSocket server in .NET or something else. +1 from me. Commented Feb 13, 2011 at 17:34
  • 14
    it makes perfect logical sense. if you want to write one server implementation that both HTML5 and Silverlight other C# clients can access then Commented Nov 27, 2011 at 4:54
  • You may want to use Fleck, available on NuGet: nuget.org/packages/Fleck Commented Apr 10, 2013 at 21:35

10 Answers 10

13

sir SuperWebSocket include a WebSocket server implementation and a WebSocket client implementation. SuperWebSocket's project page

Sign up to request clarification or add additional context in comments.

7 Comments

Note, the client implementation has not been included in latest downloadable package, please find it in source code.
Thanks for the info, gonna look into it in few days. Which standard it supports? draft-ietf-hybi-thewebsocketprotocol-04 (aka draft-hixie-thewebsocketprotocol-76)?
Yes, it is a v76 implementation.
The client in SuperWebSocket has been separated into a new project WebSocket4Net: websocket4net.codeplex.com
|
7

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:

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.

3 Comments

@Simon_Weaver The SuperWebSocket client can be found here and you'll see on the left there is a 'WebSocketClient' project/link. I can't link directly to it I'm afraid.
It is in SourceCode/mainline/Client
WebSocket client in SuperWebSocket had became WebSocket4Nethttp://websocket4net.codeplex.com/
5

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.

2 Comments

One must take care that this is supported on Windows 8 upwards, not on Windows 7 / Windows Server 2008. Quoting the MSDN page: "The class elements in the System.Net.WebSockets namespace that are supported on Windows 7, Windows Vista SP2, and Windows Server 2008 are abstract class elements."
True and if this ticket gets resolved: github.com/dotnet/corefx/issues/9503, then it would be supported in Windows 7 as well. Fingers crossed (seems like only a matter of packaging).
2

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.

Comments

2

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.

2 Comments

AFAIK, SignalR is a server, not a client.
Its not a server, but a library. SignalR allows bi-directional communication between server and client
1

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.

1 Comment

what protocol versions does it support? v00? v06?
1

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.]

Comments

0

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.

1 Comment

I have implementation in C level, while I can use it from JavaScript I also want to use it from .NET desktop application. I want to move from pull model to push model. Push new data from server to client. I am looking for Client API on .NET.
0

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.

Comments

-1

You have a few choices

1 Comment

As I mentioned for Darin, I am looking for Client API on .NET. I have server implemented, but I want to use this API not only on web development, but also on desktop client version. So far it looks very good use for web apps, also desktop and mobile clients.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.