1

I currently have a Apache2 listening on port 80, and a homemade game server running on higher unregistered port (50214). I an rewriting the game in Javascript and planning on sending the network communication over websockets on port 80 to get around the firewalls that many companies and universities put in place.

How would I go about configuring a websocket server to listen for websocket connections on 80, and unpack them and forward them to the game server listening on 50214, without interfering with apache?

What websocket server implementation should I use? and how is this usually done?

Gerald Schneider
  • 19,757
  • 8
  • 52
  • 79
Nathan
  • 258
  • 2
  • 4
  • 10

3 Answers3

5

You can't have two services both listening on the same port, so you'll need a second IP address.

Honestly, if I were implementing this, I'd just use apache on the front end, using mod_proxy to proxy your game requests through to your custom server that would only be listening on localhost. That would do away with the necessity of having two IP addresses.

EEAA
  • 108,414
  • 18
  • 172
  • 242
  • I can't afford another IP address. Can I do the same with subdomains? – Nathan Nov 15 '10 at 02:10
  • 3
    Did you read the rest of my comment? I recommended a way to do it that didn't require another IP address. – EEAA Nov 15 '10 at 03:30
  • The problem is that some organization, or some public wifi block everything but some port like port 80. So, even with Mod_Proxy this won't work because of that. Still, it's an idea but if you want to be sure that it works 100% of time, a second IP looks to be the only solution. – Patrick Desjardins Oct 05 '11 at 22:13
  • @Daok What does the port have to do with mod_proxy? You could just proxy certain paths to one server and leave the rest. – CrazyCasta Apr 11 '14 at 05:18
1

An idea: Set up a virtual host in your existing apache instance and set up an AJAX responder there, written in PHP, Python, or [your favourite language]. Your javascript client code makes AJAX calls to your apache vhost, and the AJAX responder makes whatever calls are necessary to your other server to satisfy client requests.

Steven Monday
  • 13,019
  • 4
  • 35
  • 45
  • This looks like a good idea, but I'm worried that a non-persistent connection will add a lot of latency to the game. The game client needs updates from the server around 10 times per second. Is this a problem for AJAX? – Nathan Nov 15 '10 at 02:22
  • You're right, 10 updates/second per client may be a lot to ask of AJAX. You might have to employ pipelining/boxcarring techniques, combining multiple AJAX calls within a single connection, to reduce connection overhead. – Steven Monday Nov 15 '10 at 03:29
1

Have a look at reverse HTTP proxying!

It pretty much just redirects different requests to the specific ports, you could for example:

  • have apache listening on port 8000
  • your favorite websocket server listening on 8001
  • have your reverse http proxying tool listen on port 80 and redirect example.com/ws to port 8001, and the rest to 8000

For example look at node-http-proxy, it is VERY easy to use, and there is even a simple example of websockets via socket.io right there (of course you can use whatever you prefer for a ws server).

Edit: Also the mod_proxy module of apache might be worth checking out, as an alternative (newer versions of apache also support a mod_proxy_wstunnel module).

Levite
  • 121
  • 3