--- miscJava/Test3/WebContent/WebsockTest.html 2014/02/11 12:44:13 2113 +++ miscJava/Test3/src/main/webapp/WebsockTest.html 2015/03/20 08:12:57 2446 @@ -22,7 +22,10 @@ function sendMessage() { try { var txt = $("#txt").val(); + txt = $.trim(txt); //append(txt); + if (txt == "") + return; socket.send( "CHAT#" + txt); @@ -54,6 +57,10 @@ setActTime(); } + socket.onerror = function(evt) { + append("*** Error om client websocket ***"); + } + socket.onclose = function(){ var now = new Date().getTime(); var elapsed = now - actTime; @@ -73,6 +80,11 @@ var nick = $("#nick").val(); nick = $.trim(nick); + if (nick == "") { + alert("Nick can not be empty"); + return; + } + try { socket.send( "NICK#" + nick); } catch(exception) { @@ -87,6 +99,10 @@ } }); + $(window).unload(function(){ + socket.close(); + }); + });