Websockets with ASP.NET MVC / MVVM - c#

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

Related

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.

How to push messages from API server (PHP/rest) to C# apps

I have C# apps requesting data from PHP/MySQL API server (Rest/JSON). Now I also need to push messages to the C# apps when some events occur (form submission from the web site). I searched around, and it seems that COMET, long polling, and http streaming are options. Could you please provide some suggestions on which technology makes sense here, as I am not pushing to a web browser?
In addition, if using HTTP streaming (like twitter streaming API), do I need to keep a table of HTTP connections so I know which connection to use when pushing targeted events (only to certain C# clients)? I am a bit confused, and many thanks!
Make a WCF Web Service. http://www.codeproject.com/KB/WCF/WCFWebService.aspx
To connect using PHP: http://weblogs.asp.net/gunnarpeipman/archive/2007/09/17/using-wcf-services-with-php.aspx
In micro-services environment you might want to communicate between more different coding languages in the future, that's why in Kaltura we expose every API with descriptive XML that we can use later to generate client libraries in multiple coding languages, our code generator includes client libraries for C# and PHP.
I also published several REST server examples, including C#.

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

Web Chat Application - ASP.NET/Jabber/Ajax/WCF/Comet/ReverseAjax - Issues Faced - Seeking Insights

I've been trying to build a web based chat application for the past three weeks and i'm facing issues with whatever route (programming technique/technology) i take to build it. I've explained the issues i've experienced with all of'em below. Kindly provide whatever insights you have in this.
ASP.NET-AJAX
First issue is that it is Not Really Real Time
If client hits the chat server every x seconds (constant time stamp) it is not going to be real time unless x is very very less
If x is very small like 1 second and if there are 1000 users online at the same time i think it is really going to hammer the chat server and cause scalability/performance issues
WCF-Duplex
I unfortunately wasted considerable amount of time in this trying to build a WCF duplex service which maintains all the clients and invokes the client through the channel as and when required. But i recently learnt that WCF duplex callback wont work with ASP.NET (since http is request and respond type). I was following this great article to build a duplex service.
Comet/ReverseAjax/HTTP Server Push
I'm extremely new to this technique and wonder how well enough it can scale. After my first glance on this programming technique here in wiki and the very first article on Comet by Alex here, i learned that the client always maintains an open connection (long living ajax calls) to the server which can be used by the server to push "interesting events happening in the server" to the browser (client). So how well can it scale? What if the max no of open connections exceed in IIS or any other issues like that?
Jabber Server/Client (XMPP)
I see that most of the prominent chat applications that can be seen online are making use of Jabber. I also learned that writing a Jabber server from the scratch is a tedious task. I have separate user profile store for by application. Can i integrate that with Jabber easily? Any open source Jabber servers that i can host privately? (I've seen many open source tools to build the client easily)
Any insights provided are very much appreciated.
Thank you
NLV
If you are using .NET, check out WebSync. It allows for fully scalable comet using IIS to integrate directly with your application. There is a free Community edition you can try out, along with tons of examples and chat demos.
I just recently implemented a multi-client Jabber web-app using WebSync and jabber-net.
PokeIn provides shared objects among the clients and it simply helps you to create impressively solid and fast web applications. Even if your application is hosted on multiple servers, PokeIn manages the shared objects on all of them. So, this feature will help you to create quite effective solutions. In addition to these, you will find very useful samples over there
I know this is old but if somone new founds this you should consider using SignalR
Open Source Jabber Server
Have you checked out OpenFire

Which technology should I use to expose a server files system?

I need to expose our repository which resides in our server machine to clients. The clients should be authenticated, and read write permissions are enabled. We are having doubts regarding which way to go with the implementation:
We already have client based COM layer so we can wrap it with some C# UI.
Server rest services, and then writing rest services based UI in C#/GWT/etc.
Implement WebDav protocol and get free client (windows, total commander, others)
What do you think is the best approach?
I don't know what kind of repository you are talking about, and what your clients need to do with it. But if it's plain reading and writing of files, I'd say WebDAV is the best way to go: It's supported widely across all platforms, has loads of free clients, can be set up on a Windows machine within minutes, supports SSL (I think) and is very easy to use.
If you need to do more fine-grained things like protocol changes, have you considered using source control software like Subversion, Git or Mercurial? They would give great possibilities, but the learning curve for your clients would be very steep. I wouldn't recommend this for a non-techie audience.
WebDAV or SFTP (SSH File Transfer Protocol) server would work. They offer similar functionality, with SFTP being more widespread.
I'm not sure what you have in the way of infrastructure, but I'd suggest putting the server in a DMZ so if anyone breaks in they can't do too much fdamage to the rest of your network.
How are you going to authenticate users? ASP.NET 2.0+ has some useful libraries that provide some excellent out-of-the-box capability fo managing users which integrates with FormsAuthentication; this will gove you options for identity and access management - assuming you write a asp.net front end.
What ever approach you take, I'd suggest PEN testing it - either yourselves or by a third party security specialist.

Categories

Resources