var express = require('express');
var socket = require('socket.io');
	
//Initialize app, server, and websocket
var app = express();
var server = app.listen(process.env.PORT);
var io = socket(server);
console.log("My socket server is running.");

///////////////////////////////////////////////////////
//Process events
io.sockets.on('connection', onConnection);

///////////////////////////////////////////////////////
function onConnection(socket){
	console.log('new connection: ' + socket.id);
	console.log(socket.id);
	
	socket.on('msgFromWebsite', processMessage);
}

function processMessage(msg){
	console.log('Received from website: ' + msg);
	//console.log('Sending a thank you card...');
	var result = eval(msg);
	io.sockets.emit('msgFromServer', result);
}