James Dawson
James Dawson

Reputation: 5409

Adding WebSockets support to local web server

I'm developing a multiplayer Javascript/canvas game that uses WebSockets to communicate player positions and states etc. I'm comfortable coding this in Javascript, but it's the server-side websockets stuff that I'm having trouble with.

I have no idea how I should implement WebSocket support past the client side Javascript. Do I add a module to Apache? Do I do it in PHP? Do I use something like node.js? As far as I know node.js has received a lot of praise about this sort of stuff, but I still have no idea what it really is other than a web server.

Upvotes: 1

Views: 686

Answers (1)

Jani Hartikainen
Jani Hartikainen

Reputation: 43253

I would recommend using nodejs, along with socket.io, which is a cross-browser compatible web sockets style library. It makes it really simple to write code which communicates with the server (==nodejs) in real time. It uses web sockets in browsers which support them, or other technologies in browsers which don't.

Just a note regarding PHP since you mentioned it... It is not very suitable for this in my opinion, since, as you may know, a PHP script only lives the duration of the request. This behavior makes it difficult to implement real time communication, unless you roll your own server with PHP, skipping Apache or such entirely.

Another alternative could be using Python, and perhaps something like Twisted, although you may need to implement websockets or such yourself.

Upvotes: 4

Related Questions