Skip to content

Instantly share code, notes, and snippets.

View Rob-pw's full-sized avatar

Robert White (Vix) Rob-pw

  • Nottinghamshire, England
View GitHub Profile
@Rob-pw
Rob-pw / GuessingGame.js
Created March 6, 2014 05:24
A simple guessing game, produced for Matt Hartensveld of R.I.T.
/**
* 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.
/*
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');
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