Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modern solution to WebSocket servers?

For my website I wrote a WebSockets server in C# (most preferred language to code in) that uses Fleck and it's approximately 600 lines of code. Everything seems to be working decently (a little unstable at times though. Not sure if it's a problem with my code or Fleck).

However, I want to move this from my computer to an actual domain and I'm not sure if there are any hosting providers that would support .NET console applications like that.

I was thinking that maybe I would have to rewrite it in another language like PHP but I'm slightly unsure about the whole idea. Are there any popular hosting providers that would support what I am looking for? And even if they are, is it such a good idea? I imagine it may be less secure or slower than the typical solution of using Perl, PHP, or Python for servers. (lots of P's)

Lastly, if it was a good idea to rewrite, I'm not sure of which language I would write it in. It's been a while and I'm not sure what everyone still uses. Is PHP still considered to be the most supported and secure for web servers?

Which WebSockets implementation is best suited? It took me a while to find Fleck and there seem to be twice as many PHP derivatives and I'm feeling a bit overwhelmed again. Also, a lot of posts on Stackoverflow about WebSockets are from two years ago when they were not as supported.

Sorry for my naivete and lack of focus in my question but as you can see I'm a bit confused as to what my course of action here should be and I'm looking for some insight. Thanks for reading.

like image 575
Ryan Peschel Avatar asked Oct 08 '22 01:10

Ryan Peschel


1 Answers

Probably the most popular WebSocket server is Socket.IO. It is implemented in Node (Javascript) and has fallbacks to long-polling/AJAX when WebSockets support is not available.

The most well supported implementation of WebSockets is the python pywebsocket project which is used by both Mozilla and Google for developing and testing their client browser implementations. In addition, pywebsocket is designed to easily integrate with Apache allowing you to run your web server and websocket service on the same port(s).

If your application just needs a WebSocket based messaging service and is largely peer-to-peer you might consider using a commercial WebSocket service like Pusher. That could save you from having to host and manage your own server for this.

I would not recommend PHP for WebSocket servers. Until recently there wasn't a PHP implementation that supported both the older and newer WebSocket protocol variation. The older is still used by current iOS devices and the newer IETF 6455 version of the protocol is used by Chrome, Firefox, IE10 and the Flash based WebSocket polyfill web-socket-js.

Also, you ask if PHP is still considered to be the most supported and secure for web servers. Certainly, PHP has always had great documentation and examples and very wide deployment so you could argue it's well supported. However, PHP falls near the bottom of the list in terms of security. I would certainly not rewrite your application from scratch in PHP.

If you are partial to C like languages, you might consider libwebsockets which you could use to build a C or C++ WebSocket server. Andy Green developed and maintains libwebsockets and participated in the IETF working group that developed the standard.

Ruby is another language/community that has seen a lot of uptake of WebSockets (perhaps second behind Node). The most popular websocket library for Ruby is em-weboskcet.

like image 148
kanaka Avatar answered Oct 12 '22 23:10

kanaka