Possible to use websockets on a shared hosting web server?
Asked Answered
R

2

8

I use PHP, JS, HTML, CSS. I'm willing to learn ruby or python if that is the best option.

My next project will involve live data being fed to users from the server and vice versa. I have shell access on my shared server, but I'm not sure about access to ports. Is it possible to use websockets or any other efficient server-client connection on a shared hosting account, and if so, what do I need to do?

Rhynd answered 24/3, 2013 at 15:14 Comment(2)
Setting up your own server is fun and in todays virtual world it doesn't have to be that expensive or take much time. If your traffic is moderate you can even have it for free the first year at Amazon EC2.Portugal
@Portugal hmm.. my hosting at the moment is about $6 a month - how much would I expect to pay for my own server?Rhynd
P
5

For having the best performance and full control of your setup you need "your own" server.
Today there are a huge amount of virtual server providers which means you get full control over your IP but where the physical server is still shared between many clients, meaning cheaper prices and more flexibility.

I recommend utilizing the free tier program at Amazon EC2, you can always resign after the free period. And they have many geographical locations to choose from.

Another provider in Europe that I have been satisfied with is Tilaa

You can probably find many more alternatives that suits your needs on the Webhosting talk forum

Portugal answered 24/3, 2013 at 16:11 Comment(6)
Thanks a heap for your advice :) I pay $6 (USD) for my shared hosting with hostgator at the moment. Would it be worth spending $6 on a virtual server instead? Obviously I'll get less server space, but that's not a very big problem for me, it's mainly the speed.Rhynd
It's basically two fields. If the priority is keeping a low budget and have a simple setup, @dequis solution is the way to go. If you're not afraid to do a little managing yourself and want higher quality in regards of performance and latency, exchanging a shared host for a VPS for the same amount of money is a no brainer to me. Just make sure the host has a decent reputationPortugal
I'm a little biased as I've never used shared hosting and have an easy time setting up the infrastructure myselfPortugal
I agree that this solution is better if you have some linux sysadmin skills. I also recommend looking for hosts on LEB, their top provider list and probably check uptime/performance with serverbear. These servers are usually limited by RAM (a limit that is left undefined with shared hosts) but of course let you do almost anything.Whitsuntide
I love you guys! Serverbear is awesome! Thank you both so much.Rhynd
Note that serverbear is just part of it - ALWAYS check for opinions from existing users on lowendbox/lowendtalk/webhostingtalk. Stuff like proper tech support is extremely important (VPSes are usually unmanaged, but that doesn't mean they don't have responsibilities)Whitsuntide
W
3

Until some weeks ago, websockets deployment required either a standalone server running on a different port, or server side proxies like varnish/haproxy to listen on port 80 and redirecting normal http traffic. The latest nginx versions added built-in support for websockets, but unless your hosting provider uses it, you're out of luck. (note that I don't have personal experience with this nginx feature)

Personally I find that for most applications, websockets can be replaced with Server-sent events instead - a very lightweight protocol which is basically another http connection that stays open on the server side and sends a stream of plaintext with messages separated by double newlines.

It's supported in most decent browsers, but since this excludes internet explorer there are polyfills available here and here

This covers one side of the connection, the one that is usually implemented with long-polling. The other direction can be covered the usual way with XHR. The end result is very similar to websockets IMO, but with a bit higher latency for client->server messages.

Whitsuntide answered 24/3, 2013 at 15:48 Comment(2)
Great info, thanks! But I'm wondering whether the server-sent/XHR is reasonable for a live stream of data between the server and the user. Isn't it a standard idea that one should use sockets for this sort of thing?Rhynd
Well, the server-sent stream is a socket - one that uses the same http connection. It's kept alive and messages are received by the client as soon as the TCP connection between both sides would allow. The client->server communication is weaker for applications that require low latency, as it needs to establish an http connection from scratch. It really depends on what kind of latency requirements your application has. Stuff like a live chat is possible - a realtime arcade browser game isn't.Whitsuntide

© 2022 - 2024 — McMap. All rights reserved.