2

I have just started HTML5 game development, I made a couple of games using the canvas, accessing it with Javascript.

I wonder, though, about how I can make multiplayer online games. Do I necessarily need to use server side stuff for this?

I've heard of HTML5 Sockets, are there other alternatives?

Thank you.

EDIT: Any simple example or links are very much appreciated.

David Gomes
  • 5,644
  • 16
  • 60
  • 103
  • I think http://browserquest.mozilla.org/ is a good example. Source code: https://github.com/mozilla/BrowserQuest – 19greg96 Apr 22 '12 at 20:25
  • http://www.multiplayerpiano.com/ is something I'd love to see the source code of, it uses socket.io. – David Gomes Apr 22 '12 at 20:31
  • @user996058 I posted an early version of the multiplayerpiano.com server: https://gist.github.com/1775362 -- it's really just dead simple :) – Brandon Lockaby Apr 22 '12 at 22:52

1 Answers1

4

You need a server, P2P doesn't work yet between browsers. See: Do I need a server to use HTML5's WebSockets?

Websocket (HTML5 sockets) is a way to have a bi-directional open connection between the browser and your server. Otherwise you'll have to work using XHR (aka Ajax) which is pull only. Mozilla wrote a great article explaining how they built: BrowserQuest (or just play it: http://browserquest.mozilla.org/)

Alternatives are generally based on Flash XMLSocket!

Community
  • 1
  • 1
greut
  • 4,305
  • 1
  • 30
  • 49
  • I do have a server, FTP server where I host my files, I'm guessing that's enough, right? – David Gomes Apr 22 '12 at 20:32
  • you have to run a command in a console to start a socket.io server as far as I know. – 19greg96 Apr 22 '12 at 20:33
  • @user996056 nope, you need a specific web server. One that can accept web sockets (https://en.wikipedia.org/wiki/Comparison_of_WebSocket_implementations) – greut Apr 22 '12 at 20:36