/[projects]/miscJava/Test3/WebContent/WebsockTest.html
ViewVC logotype

Contents of /miscJava/Test3/WebContent/WebsockTest.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2111 - (show annotations) (download) (as text)
Tue Feb 11 09:52:51 2014 UTC (10 years, 3 months ago) by torben
File MIME type: text/html
File size: 1730 byte(s)
add note on haproxy timeout
1 <html>
2 <head>
3 <title>Test3 :: Websocket Test</title>
4 <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
5
6 <script type="text/javascript">
7
8 var actTime = 0;
9 var socket = null;
10
11 function setActTime() {
12 actTime = new Date().getTime();
13 }
14
15 function append(str) {
16 var log = $("#log");
17 log.val( log.val() + str + "\n")
18 }
19
20 function sendMessage() {
21 try {
22 var txt = $("#txt").val();
23 append(txt);
24
25 socket.send(txt);
26
27 $("#txt").val("");
28 setActTime();
29
30 } catch(exception) {
31 append(exception);
32 }
33 }
34
35 $( function() {
36 $("#log").val("");
37 append("starting app");
38
39 try {
40 var url = "ws://" + document.location.host + "/Test3/wstest";
41 append("Opening connection to " + url)
42
43 socket = new WebSocket(url);
44
45 socket.onopen = function() {
46 append("Socket has been opened!");
47 setActTime();
48 }
49
50 socket.onmessage = function(msg){
51 append(msg.data); //Awesome!
52 setActTime();
53 }
54
55 socket.onclose = function(){
56 var now = new Date().getTime();
57 var elapsed = now - actTime;
58 elapsed = elapsed / 1000;
59
60 append('Connection closed after ' + elapsed + ' seconds of inactivity');
61 }
62 } catch(exception){
63 append(exception);
64 }
65
66 $("#btn").click( function() {
67 sendMessage();
68 });
69
70 $(document).keypress(function(e) {
71 if(e.which == 13) {
72 sendMessage();
73 }
74 });
75
76 });
77
78
79 </script>
80
81 </head>
82 <body>
83
84 <h2>Websocket test chat</h2>
85
86 <textarea rows="30" cols="160" id="log" readonly></textarea>
87 <br>
88 <input size=120 type="text" name="txt" id="txt">
89 <button id="btn">Submit</button>
90
91 <br><br>
92 <font size="2">
93 If using websockets with haproxy look into <code>timeout tunnel</code> option.
94 </font>
95
96 </body>
97 </html>

  ViewVC Help
Powered by ViewVC 1.1.20