$(document).ready(function () { console.log('try connection'); var socket = io();//.connect('http://' + document.domain + ':' + location.port); socket.on('connect', function() { console.log('connected'); socket.emit('message', {data: 'I\'m connected!'}); }); socket.on('message', function(data) { }); });