Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using WebSockets in a C# Web Application?

I know its possible to use WebSockets within C# using a console application running along side the web application but Im wondering if its possible to use the requests on the C# web application to create the WebSockets.

I've been looking through ASP.Net and Im starting to think it wont be possible unless I use straight up C# and create my own HTTP server and then use the same socket object to generate Web Sockets (similar to the way Node.js and Socket.IO work).

Any thoughts on ways to include WebSockets on a C# web application without having multiple servers / projects?

like image 893
sixones Avatar asked Jun 10 '10 13:06

sixones


4 Answers

It's possible to host a WebSockets server within the context of an ASP.NET. However, you'll need to be aware that the ASP.NET application can be restarted which means the server will be shut down and will need to be re-established along with the ASP.NET application.

Hosting the WebSockets application within a separate Windows Service would provide greater reliability in the socket server, but then will require IPC to share data between the ASP.NET application and the Windows Service.

So, there's a trade-off to discuss. It depends on how sensitive your client code is to connection loss and re-establishment. If this is handled sufficiently then hosting within ASP.NET will be fine.

Note that while WebSockets are new to HTML, the concept has existed for many years with Flash and Java Applets. Especially with Flash it's commonly used for online games and web-based chat.

like image 133
Samuel Neff Avatar answered Oct 02 '22 05:10

Samuel Neff


The source code of SuperWebSocket contains a web project which run a socket server in website. http://superwebsocket.codeplex.com/

like image 29
jzywh Avatar answered Oct 02 '22 05:10

jzywh


PokeIn 2.0 has built in WebSocket feature and it doesn't require any special environment to work. Details available from here

like image 41
Zuuum Avatar answered Oct 02 '22 05:10

Zuuum


There will be is built in support for websockets client and server in asp.net 4.5 and IIS8.

See: http://www.asp.net/vnext/overview/aspnet/whats-new#_Toc318097383

like image 40
Geo Avatar answered Oct 02 '22 06:10

Geo