This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by robert on 06/03/14. | |
*/ | |
"use strict"; | |
var readline = require('readline'), | |
rl = readline.createInterface(process.stdin, process.stdout); | |
/** | |
* This is our game object, we can create instances of this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
If socket.io is running on port 80, here is the shorthand script tag | |
<script src="/socket.io/socket.io.js"></script> | |
Else, you'll have to specify the port and host. | |
<script src="http://localhost:8080/socket.io/socket.io.js"></script> | |
*/ | |
//If port 80 | |
//var socket = io.connect(); | |
var socket = io.connect('http://localhost:8080'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var io = require('socket.io').listen(8080); | |
//Listen for the connection event to be fired, this is done after a new successful connection is made to a client | |
//Provides a reference to the opened socket / client, connection specific communication done via ref. | |
io.sockets.on('connection', function (socket) { | |
//First, we'll emit (send) a Message Of The Day to our client. | |
//In this case, the event handle is 'motd' and the data is "Welcome to my server!" | |
socket.emit('motd', "Welcome to my server!"); | |
//Now we'll add an event handler for the 'message' event, once fired it will call the function |