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?

sawa
  • 165,429
  • 45
  • 277
  • 381
  • 1
    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](https://aws.amazon.com/free/). – baloo Mar 24 '13 at 15:56
  • @baloo hmm.. my hosting at the moment is about $6 a month - how much would I expect to pay for my own server? –  Mar 24 '13 at 16:02

2 Answers2

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

baloo
  • 7,635
  • 4
  • 27
  • 35
  • 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. –  Mar 24 '13 at 16:15
  • 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 reputation – baloo Mar 24 '13 at 16:28
  • I'm a little biased as I've never used shared hosting and have an easy time setting up the infrastructure myself – baloo Mar 24 '13 at 16:29
  • 1
    I agree that this solution is better if you have some linux sysadmin skills. I also recommend looking for hosts on [LEB](http://www.lowendbox.com/), their [top provider list](http://www.lowendtalk.com/wiki/top-providers) and probably check uptime/performance with [serverbear](http://serverbear.com/). These servers are usually limited by RAM (a limit that is left undefined with shared hosts) but of course let you do almost anything. – dequis Mar 24 '13 at 16:36
  • I love you guys! Serverbear is awesome! Thank you both so much. –  Mar 24 '13 at 17:09
  • 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) – dequis Mar 24 '13 at 17:19
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.

dequis
  • 2,100
  • 19
  • 25
  • 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? –  Mar 24 '13 at 15:58
  • 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. – dequis Mar 24 '13 at 16:16