Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am interested in making a game that I currently have a co-op experience, however I'm curious as to the best method of implementing this in HTML5.

I have made games before using straight C sockets, and also with the Net library for SDL.

What are some of my best options for doing this in a canvas-based environment?

At present, all I can come up with are either AJAX/database solutions (with a high refresh rate), or somehow implementing a PHP server that would funnel the data through sockets.


The overall gameplay would be a 2.5D platformer-ish type of game, so both clients would need to be continually updated with player positions, enemy positions, projectiles, environmental data, etc.

share|improve this question

closed as off-topic by Josh Petrie Dec 9 '13 at 17:29

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions that are about "which tech to use" are outside the scope of the site. For more information, see this meta post" – Josh Petrie
If this question can be reworded to fit the rules in the help center, please edit the question.

1  
When websockets (en.wikipedia.org/wiki/WebSockets) is finalized (and implemented etc) that would probably be a good way, until then I think AJAX (without the X, no XML required for this) would probably be the best way (still not a very good way I suppose). –  Kevin van der Velden Feb 4 '11 at 20:32
    
Seems that support for web sockets is dropping fast... –  espais Feb 4 '11 at 21:19
    
Do you want to make a stand or a game? If you want to make game; dont bother go for html5. –  stefan Feb 5 '11 at 4:35
    
@stefan: why not both? just because it isn't finalized yet doesn't mean that i can't work with it! –  espais Feb 7 '11 at 13:49
add comment

9 Answers 9

up vote 11 down vote accepted

Socket.IO offers a system built on top of several other layers (including websockets, flash, comet techniques) with graceful selection.

Node.js is one option for running it server side.

share|improve this answer
add comment

See this answer:

You can, however, use Flash where available to provide your script with a fallback until WebSocket is widely available. Gimite's web-socket-js is one free example of such. However you are subject to the same limitations as Flash Sockets then, namely that your server has to be able to spit out a cross-domain policy on request to the socket port, and you will often have difficulties with proxies/firewalls. (Flash sockets are made directly; for someone without direct public IP access who can only get out of the network through an HTTP proxy, they won't work.)

share|improve this answer
add comment

Comet” is probably an umbrella term that you could make use of here. WebSockets will be a more desirable option though (when they’re happy that it is safe).

share|improve this answer
add comment

Node.js is the answer. I've used it to develop a realtime multiplayer shooting game, and it took about 1 month from start to finish. It presented some unique challenges, such that it needed to have minimal latency, and all players must stay in sync within another for the concept to work.

The client side, and server side are both written in javascript and share classes / logic between each other. That starts to count when trying to fix bugs, as you don't have to implement everything twice.

The game has been up, for about 2 months, without being restarted and thousands of matches have been played.

Socket.io is an implmentation of sockets and uses node.js, however it is too bloated at this point for a game. There are other websocket implementations on github for node.js and also examples of games using it.

share|improve this answer
add comment

You could always just use AJAX and some sort of message queue. ActiveMQ is a good example. You run ActiveMQ on the server, then your JavaScript can send and receive messages. Just make each player have a unique name, and send messages to the other player.

share|improve this answer
add comment

You could try to use http://easywebsocket.org/, it's easy to implement and is a serverLess solution based on websocket :)

share|improve this answer
add comment

Currently I am using this: http://code.google.com/p/phpwebsocket/ as my socket server to test. It makes calls to the C sockets you are use to. May be of some service.

share|improve this answer
add comment

We have been working on a multi-player platform that you might find interesting. You can see our project at www.16cubes.com -- we are providing a simple javascript layer to do peer to peer communication. It is somewhat based on the Comet principle, and we have plans to move to using websockets as it becomes a bit more standardized. On the other hand, we are providing some features off the shelf .. like automatic opponent matching, game chat, facebook friends one-click invitation etc.

We have a demo tic-tac-toe, you can probably get a better idea if you see it. And yes, you can play anonymously too. No registration required, if you don't want. There's less than 10 javascript API's you need to code against, and its available at www.16cubes.com/documentation

We are actively looking for feedback, so let us know both good and bad

share|improve this answer
add comment

Have a look at this framework I created specifically for creating realtime multiplayer html5 games using node.js in a Client/Server approach. Where the server runs the game simulation, and players only send inputs.

demo: http://vimeo.com/24149718

repo: https://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs

share|improve this answer
add comment

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