$(function() {
  var socket = new WebSocket("ws://" + window.location.host + "/");

  socket.onmessage = function(message){
    console.log('got a message: ')
    console.log(message)
  }

});

$(function() {
  var socket = new WebSocket("ws://" + window.location.host + "/");

  socket.addEventListener('message', function(message){
    console.log('got a message: ')
    console.log(message)
  });

});

Use addEventListener rather than onmessage