Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Sorry you had to read that twice.

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 implemenation should I use? and how is this usually done? help a noob. thanks sf.

share|improve this question

3 Answers 3

up vote 5 down vote accepted

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.

share|improve this answer
    
I can't afford another IP address. Can I do the same with subdomains? –  Nathan Nov 15 '10 at 2: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 3: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 5 '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 at 5:18

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.

share|improve this answer
    
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 2: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 3:29

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).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.