16

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?

6
  • Can you provide a link to how to use WebSockets with a console application? I didn't think .NET supported websockets at all. Commented Jun 10, 2010 at 13:59
  • I found a couple: nugget.codeplex.com extjs.com/forum/showthread.php?99842-WebSocket-server-in-C codeproject.com/KB/webservices/c_sharp_web_socket_server.aspx They all work with Mono or .Net. Commented Jun 10, 2010 at 14:09
  • @John Saunders, not everything that needs to be done is written into the .NET BCL. Some stuff has to be implemented on top of what .NET already provides. Commented Jun 10, 2010 at 14:32
  • @Sam: I was reacting to him saying, "I've been looking through ASP.NET". It seemed he was only looking in the BCL. Commented Jun 10, 2010 at 16:41
  • @John Saunders, but he also said in the first sentence that he knows how to use WebSockets in a console app. Commented Jun 10, 2010 at 16:51

5 Answers 5

11

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.

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

2 Comments

Thanks, I figured that would be the case, I was thinking the trade-off would be using a web application project in ASP.Net, a WebSocket server in C# and a C# library (containing all the models) each server project has access to. The project Im working on doesn't actually need to share the data between the 2 server projects as the 2 protocols handle different data paths. However containing everything in 1 project would be a lot nicer! Do you have any links to examples or anything about using WebSockets in ASP.Net?
@sixones, there's really no difference in actual implementation when hosted in ASP.NET instead of a windows service. Just initialize it at application initialize event instead of the service OnStart call.
5

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

Comments

3

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

Comments

3

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

Comments

3

Check out the .net client implementations from Kaazing. Using these clients you can connect to any websocket server.

1 Comment

I was wondering about a server not a client implementation, thanks though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.