Skip to content

Instantly share code, notes, and snippets.

@brlafreniere
Created March 16, 2015 15:30
Show Gist options
  • Save brlafreniere/05d6dfe97661bc37b543 to your computer and use it in GitHub Desktop.
Save brlafreniere/05d6dfe97661bc37b543 to your computer and use it in GitHub Desktop.
var app = require('./app');
var http = require('http').Server(app);
var io = require('socket.io')(http);
var port = 3000;
io.on('connection', function(socket) {
console.log("A user connected.");
});
io.on('message', function(data) {
// not seeing this in the server console
console.log('received message');
});
http.listen(port, function(err, res) {
console.log("Listening on port " + port);
});
$(document).ready(function () {
var socket = io();
$('#send').click(function (event) {
// I am seeing this in the client console
console.log("Send button clicked.");
var data = {};
data.message = $('#message-box').val();
data.nickname = 'billy';
socket.emit('message', data);
$('#message-box').val("");
});
socket.on('receive-message', function(data) {
$('chat-window').append("<div>"+data.nickname+": "+data.message+"</div>");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment