$(document).ready(function(){ function debug(str){ $("#debug").append("

" + str); }; ws = new WebSocket("ws://localhost:8080/"); ws.onmessage = function(evt) { $(".msg").prepend("

"+evt.data+"

"); }; ws.onclose = function() { debug("socket closed"); }; ws.onopen = function() { debug("connected..."); //ws.send("hello server"); // ws.send("hello again"); }; });