/[projects]/miscJava/Test3/src/main/webapp/WebsockTest.html
ViewVC logotype

Diff of /miscJava/Test3/src/main/webapp/WebsockTest.html

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

miscJava/Test3/WebContent/WebsockTest.html revision 2112 by torben, Tue Feb 11 10:02:13 2014 UTC miscJava/Test3/src/main/webapp/WebsockTest.html revision 2446 by torben, Fri Mar 20 08:12:57 2015 UTC
# Line 22  function append(str) { Line 22  function append(str) {
22  function sendMessage() {  function sendMessage() {
23          try {          try {
24                  var txt = $("#txt").val();                  var txt = $("#txt").val();
25                  append(txt);                  txt = $.trim(txt);
26                    //append(txt);
27                    if (txt == "")
28                            return;
29                                    
30                  socket.send(txt);                  socket.send( "CHAT#" + txt);
31                                    
32                  $("#txt").val("");                  $("#txt").val("");
33                  setActTime();                  setActTime();
# Line 54  $( function() { Line 57  $( function() {
57                      setActTime();                      setActTime();
58                  }                  }
59                    
60                    socket.onerror = function(evt) {
61                            append("*** Error om client websocket ***");
62                    }
63            
64                  socket.onclose = function(){                  socket.onclose = function(){
65                          var now = new Date().getTime();                          var now = new Date().getTime();
66                          var elapsed = now - actTime;                          var elapsed = now - actTime;
# Line 69  $( function() { Line 76  $( function() {
76                  sendMessage();                  sendMessage();
77          });          });
78                    
79            $("#btnNick").click( function() {
80                    var nick = $("#nick").val();
81                    nick = $.trim(nick);
82                    
83                    if (nick == "") {
84                            alert("Nick can not be empty");
85                            return;
86                    }
87                    
88                    try {
89                            socket.send( "NICK#" + nick);                  
90                    } catch(exception) {
91                            append(exception);
92                    }
93                    
94            });
95            
96          $(document).keypress(function(e) {          $(document).keypress(function(e) {
97                  if(e.which == 13) {                  if(e.which == 13) {
98                          sendMessage();                          sendMessage();
99                  }                  }
100          });          });
101                    
102            $(window).unload(function(){
103                    socket.close();
104            });
105            
106  });  });
107    
108    
# Line 88  $( function() { Line 116  $( function() {
116  <textarea rows="30" cols="160" id="log" readonly></textarea>  <textarea rows="30" cols="160" id="log" readonly></textarea>
117  <br>  <br>
118  <input size=120  type="text" name="txt" id="txt">  <input size=120  type="text" name="txt" id="txt">
119  <button id="btn">Submit</button>  <button id="btn">Submit</button><br><br>
120    
121    <input size=20  type="text" name="nick" id="nick">
122    <button id="btnNick">Set Nick</button><br><br>
123    
124  <br><br>  <br><br>
125  <font size="2">  <font size="2">

Legend:
Removed from v.2112  
changed lines
  Added in v.2446

  ViewVC Help
Powered by ViewVC 1.1.20