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?
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.
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.
Have a look at reverse HTTP proxying!
It pretty much just redirects different requests to the specific ports, you could for example:
example.com/ws
to port 8001, and the rest to 8000For 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 amod_proxy_wstunnel
module).