5

I have a dilemma here.

Trying to build a simple turn based two player game, and I've been trying out Node.js and Socket.IO, as I've seen recommended in a question:

Multiplayer JavaScript game built with Node.JS - Separating players

This answered most of my big issues, however still few remain. Since I've also build a chat room to test it out and it works nicely.

However, is there really any point of using node.js for that kind of game? Can it be done with HTML5 WebSockets?

Community
  • 1
  • 1
rexdefuror
  • 573
  • 2
  • 13
  • 33
  • 1
    Not sure I follow your question. Socket.io is a layer that uses WebSockets when available, with failovers to other methods when it is not. WebSockets require a server component (you cannot direct connect to another client), hence where NodeJS comes in. NodeJS isn't the only WebSocket server out there, but it is one of them. – Matt Sep 10 '13 at 15:00
  • Hmm, I seem to have misunderstood the point of node.js there... But I think you mostly answered my question. :) If you know some good tutorials for node.js or any other WebSocket server please do link. Thanks. – rexdefuror Sep 10 '13 at 15:03
  • 1
    http://stackoverflow.com/questions/1253683/what-browsers-support-html5-websocket-api/2700609#2700609 – apsillers Sep 10 '13 at 15:05
  • Since your interest is in WebSockets, I would start with the Socket.IO examples directly on their website. See http://socket.io/#how-to-use. – Matt Sep 10 '13 at 15:07
  • Thanks apsillers and Matt for your help :) – rexdefuror Sep 10 '13 at 15:20

1 Answers1

11

I'm using knife to butter my bread.
However, is there really any point of using knife for that purpose? Can it be done just with butter?

Node.js - is Application Platform for many different use cases, starting from small command-line tools, ending with big applications like LinkedIn Mobile, MySpace and games as well.
As this platform has a lot of web related libraries and tools - it is very neat to use it in that case, especially coding in JavaScript (what can be better for web?).
Socket.IO - is specific library that utilizes many web transports in attempt to establish reliable real-time bi-directional communication layer between web browser and server (node.js in this case).

HTML5 is set of technologies that are implemented by browser vendors (Chrome, Firefox, IE, etc). This technologies like canvas, webgl, audio/video elements, websockets - are it self dependant on many things. In case with WebSockets - they have to talk to some server. And without any server - they are useless.

If you choose to use node.js as your server platform, then you have few options, most common would be using socket.io or pure websockets.
Most common multiplayer architecture especially in the web is client<>server. So that means there is at least one centralized server that clients talk to. In this case server will do most decision making and all game logic, and send only required data to clients for rendering.
There is another option: p2p (Peer to Peer), and is possible with WebRTC but not yet ready for commercial use due to lack of implementations across most common browsers. In this case all clients should limulate same game state and make decisions them self with cross-approval over all (mostly) peers in game session.
I recommend to start from server<>client as it suits most of cases as well is simplier in many ways (and vice-versa too :) ).

You also can use any other server side platform like, PHP, .Net, Java, Ruby, Python, C/C++ and any other. It is matter of comfort and access to useful libraries that helps you on the way of development.

moka
  • 22,846
  • 4
  • 51
  • 67
  • 1
    Yeah, I noticed after first comment how wrong I was. Nice analogy though. Thanks for your trouble. – rexdefuror Sep 10 '13 at 15:21
  • No problem :) It is important to understand generalized concepts over tech and game development ideas, and then it will be much easier to 'navigate'. – moka Sep 10 '13 at 15:24