adding lan support in a HTML5 game using javascript

i want to add lan support to tic-tac-toe game which is a HTML5 canvas based, so that two players can easily play. how can i do it using javascript/node.js?

OK, I'm assuming all of your HTML5 game is finished and you're distributing it with the server that hosts it. (Otherwise you're stuck to just the browser, which can't do all the awesome node.js net stuff, I am describing.)

NB: You need to have node.js running on both clients. Otherwise you can't do LAN-only without a central server's involvement.

  1. One of your clients has decided they want to host a LAN game
  2. The node.js server running on that client starts to listen on a port
  3. That server find out its local IP Get local IP address in node.js
  4. Options:
    • Your players can manually tell each other the IP of the hosting server
    • Your hosting server sends out broadcast messages to its local subnet, informing them that it's hosting a game
    • Your other client server scans for IPs in its local subnet to find any hosting gameservers (Tries to open the pre-determined port your hosting server is listening on.)
  5. The other node.js client opens a connection to the hosting server.

Done.