HTML5 WebSockets Client for .NET - c#

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?

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

Related

Can I use gRpc as a replacement of SignalR for updating notification on client-side?

I'm new to gRpc and now learning this tech
I'm wondering if gRpc can replace SignalR for updating notification bar on my client-side app (React).
Is that the case? or should I keep using SignalR for this matter?
(I'm asking it just to make sure I understand the purpose of the gRpc tech, by few articles I read it's more a web API replacement and few others compare it to SignalR)
Thanks!
y-me
Assuming you meant browser-based clients, then NO you cannot use gRPC. The gRPC protocol relies on HTTP/2 framing and in particular the ability to send and receive HTTP trailers. While browser themselves can and do use HTTP/2, current browser APIs (XHR/Fetch) don't expose HTTP/2 semantics.
There is however an alternative protocol, gRPC-web, that supports a subset of gRPC functionality you can utilize from a browser-based application. Given that it is a different protocol, your server will need to support it or you will need to employ a proxy like Envoy that can translate gRPC-web calls to gRPC.
I can't answer your question has if it is usable for Server/Client communications, just offer some thoughts. SignalR is made for the purpose of real time communications between Client and Server because of it's adaptability, and gRPC by it's constraints (HTTP/2 and HTTPS) is more reserved for backend micro-services communications.

Any WebSocket server framework on ASP.Net Core?

Is there any high-level framework for WebSocket server in ASP.Net Core apps?
I saw the basic websocket support via Microsoft.AspNetCore.WebSockets.Server nuget described on the net and SO questions.
Is there something more high-level? SignalR would be a great example, but it's planned for 2017. Is there something available right now?
SignalW
Efficient, has Hub and groups just like SignalIR does, and most importantly it does not force you to use a particular message format or JSON. You can adapt any protocol you like, and I use it for JSON-RPC
Websocket-Manager
A decent implementation. It's very well documented and there is a blogpost explaining how to re-create it yourself. The disadvantage is that it forces you to use JSON and a spesific message format, which is not ideal if you have other clients that aren't .Net
Websocket-sharp
This a server that does not rely on ASP.NET Core, it is just a websocket server and that's it - no REST, serving files, etc. This can be important if you are looking to add websocket connectivity to an application that has nothing to do with being a webserver, like a game. Starcraft uses websockets and protobuff for bot and AI development. This does work with unity.
There is currently a discussion about .Net Core compatiability, but I believe it's not quite done yet.

.NET WebSocket client and server library

I'm looking for an open source, cross-platform, actively maintained .NET library which provides websocket functionality for both clients and servers, in such a way that most of the code (after connection is established) can use the same abstraction regardless of which side of the connection it is on. Ideally, it would be a platform-independent implementation of System.Net.WebSockets, but I don't really care if it defines its own types, so long as there's some single abstract WebSocket class that can be shared by client and server code.
Things that I've looked at and that did not qualify (but correct me if I'm wrong):
System.Net.WebSockets (client only, Win8+ only)
WebSocket4Net (client only)
WebSocket Portable (client only)
Fleck (server only)
WebSocketListener (server only)
SuperWebSocket (server only)
Owin.WebSocket (server only)
PowerWebSockets (proprietary)
XSockets (proprietary)
Alchemy Websockets (last release in 2012, many active bugs in the tracker with no answers)
The only one that I could find that seems to be matching the requirements is websocket-sharp. However, what worries me there is the sheer number of opened issues in the tracker along the lines of clients unable to connect, invalid data frames etc - it sounds like it's not very mature yet.
Are there any other candidates that match my requirements that I have missed? Or am I wrong about any of the libraries listed above being client/server only?
Look at Microsoft's SignalR. SignalR is a higher level abstraction around websockets. SignalR also allows the client to be written in .NET (C#). From the SignalR documentation:
The SignalR Hubs API enables you to make remote procedure calls (RPCs) from a server to connected clients and from clients to the server. In server code, you define methods that can be called by clients, and you call methods that run on the client. In client code, you define methods that can be called from the server, and you call methods that run on the server. SignalR takes care of all of the client-to-server plumbing for you.
SignalR also offers a lower-level API called Persistent Connections. For an introduction to SignalR, Hubs, and Persistent Connections, or for a tutorial that shows how to build a complete SignalR application, see SignalR - Getting Started.
One another solution is to make use of Edge.js. This is a .NET library that utilizes Node.js. You could let Node.js to act as both the server and client of the WebSocket channel. And then utilize Edge.js to act as the bridge between the worlds, Nodejs and the .Net. Have a look at the following, there are plenty of samples as well. github.com/tjanczuk/edge/tree/master#scripting-clr-from-nodejs. Both are excellent frameworks that are actively maintained.
However the use of Edge.js does introduce an additional dependency, node.js
You can take a look at the WebSocketRPC. The library is based on the System.Net.WebSockets and it is portable. Moreover, it auto-generates JavaScript client code and has support for ASP.NET Core.
I suggest you try-out samples first located inside the GitHub repository.
Disclaimer: I am the author of the library.

How to approach Android development in C# where the app will need internet access?

I will need to begin development on an Android applicaiton soon. This application will need to communicate with a server over the internet. I hope to be able to do my development in C# in one of the various development environments that appear to be available, e.g. Mono for Android.
My questions are:
What is the best framework for developing C# applications for Android?
What will give me the most flexibility for communicating over the Internet? (My boss tells me that existing c# --> Android frameworks have limitations regarding internet access)
What are the limitations that I can expect to face doing this with C#?
What are your experiences with taking this approach?
For communication over internet there might be many ways, depends on your needs.
It can be HTTP requests with some POST data, or proper low-level communication over Sockets.
If you need to communicate with web service that accepts POST requests and provides some data in XML (for example), then you might use HTTP request way.
If you have real-time server that servers Sockets communication, then you might want to use Sockets with some data protocol over it (based on which data protocol server accepts / serves).
There is full support for establishing Sockets communication using MonoDroid with. It is almost the same as with x86 .Net implementation on Windows.

Websockets with ASP.NET MVC / MVVM

Earlier today I came across Kaazing's WebSocket API for HTML5.
Looks fantastic, but as I am only now researching WebSocket possibilities for real-time financial updating, I would like to hear some recommendations, and pitfalls to avoid when planning out this architecture.
I'm looking at ASP.Net MVC, and possibly some WPF/Silverlight MVVM.
Are there other WebSocket API's that are better (and why), and some good examples?
Also, what kind of traffic can WebSockets handle? I mean, if we have over a million users on a system updating real-time, how do hardware requirements change because the software architecture implements WebSockets?
A late answer. Here is a WebSocket Server (framework) that is based on .NET and has support for modelbinding / controller and validations etc. in a way that reminds of MVC. It is very easy to get started using it. Just create a new MVC3 Project and type:
Install-Package XSockets
Using the Package Manager Console in Visual Studio
More info on http://xsockets.net
And yes, it supports RFC6455 and Hibi00 and has a fallback for "older" browsers.
I figured I'd come back at this, now that I have a solution ready for production. I took a look at a few vendors that basically charge a lot of money for something you can essentially build yourself. They all have good products, and if your time to market is critical, those prefab options may be the best in the short run.
After poking around with Node.JS with Socket.IO, I shifted my attention to SignalR - an asynchronous signaling library for .NET to help build real-time, multi-user interactive web applications, and used the hub implementation.
It manages all the heavy lifting and connection building with just a few lines of JavaScript, and automatically selects the appropriate transport protocol for the connection.
For a load-balanced environment, implementation of a caching server such as Redis is required.
Here's a C# implementation of a Web Socket client and server on CodeProject:
Web Socket Server
I think following links will help you..
The WebSockets prototype with Silverlight, HTML Bridges and JavaScript
Silverlight and WebSockets (Mike Taulty's blog)
https://github.com/Olivine-Labs/Alchemy-Websockets
Here's an open source websocket server and client library. C#/Javascript. Includes fallback to flash sockets for browsers that don't have websockets yet. Tested on most web browsers including mobile ones, works everywhere.
Realtime financials? I don't know how many connections you plan on handling but this one is also the most scalable solution available right now.
Although the number of browsers are quite limited for websockets, mobile browsers have support for that. But i would be considering the use of more cross browser friendly choices like PokeIn reverse ajax library

Categories

Resources