--- miscJava/Test3/WebContent/WebsockTest.html 2014/02/11 09:52:51 2111 +++ miscJava/Test3/WebContent/WebsockTest.html 2014/02/11 13:02:21 2116 @@ -13,16 +13,21 @@ } function append(str) { + var d = new Date(); + var dateStr = "[" + d.toLocaleTimeString() + "] "; var log = $("#log"); - log.val( log.val() + str + "\n") + log.val( log.val() + dateStr + str + "\n") } function sendMessage() { try { var txt = $("#txt").val(); - append(txt); + txt = $.trim(txt); + //append(txt); + if (txt == "") + return; - socket.send(txt); + socket.send( "CHAT#" + txt); $("#txt").val(""); setActTime(); @@ -67,12 +72,33 @@ sendMessage(); }); + $("#btnNick").click( function() { + var nick = $("#nick").val(); + nick = $.trim(nick); + + if (nick == "") { + alert("Nick can not be empty"); + return; + } + + try { + socket.send( "NICK#" + nick); + } catch(exception) { + append(exception); + } + + }); + $(document).keypress(function(e) { if(e.which == 13) { sendMessage(); } }); + $(window).unload(function(){ + socket.close(); + }); + }); @@ -86,7 +112,10 @@
- +

+ + +