blob: 25e08e7f2e1a76903ff2d5a6d3b043afc3ca1561 [file] [log] [blame]
tyoshino@chromium.org78056712010-12-16 07:41:261<!--
2Copyright 2010, Google Inc.
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are
7met:
8
9 * Redistributions of source code must retain the above copyright
10notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above
12copyright notice, this list of conditions and the following disclaimer
13in the documentation and/or other materials provided with the
14distribution.
15 * Neither the name of Google Inc. nor the names of its
16contributors may be used to endorse or promote products derived from
17this software without specific prior written permission.
18
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30-->
31
32<!--
33A simple console for testing WebSocket server.
34
35Type an address into the top text input and click connect to establish
36WebSocket. Then, type some message into the bottom text input and click send
37to send the message. Received/sent messages and connection state will be shown
38on the middle textarea.
39-->
40
41<html>
42<head>
43<title>WebSocket console</title>
44<script>
45var socket = null;
46
47var addressBox = null;
48var logBox = null;
49var messageBox = null;
50
51function addToLog(log) {
52 logBox.value += log + '\n'
53 // Large enough to keep showing the latest message.
54 logBox.scrollTop = 1000000;
55}
56
57function send() {
58 socket.send(messageBox.value);
59 addToLog('> ' + messageBox.value);
60 messageBox.value = '';
61}
62
63function connect() {
64 socket = new WebSocket(addressBox.value);
65
66 socket.onopen = function () {
67 addToLog('Opened');
68 };
69 socket.onmessage = function (event) {
70 addToLog('< ' + event.data);
71 };
72 socket.onerror = function () {
73 addToLog('Error');
74 };
75 socket.onclose = function () {
76 addToLog('Closed');
77 };
78
79 addToLog('Connect ' + addressBox.value);
80}
81
82function init() {
83 var scheme = window.location.protocol == 'https:' ? 'wss://' : 'ws://';
84 var defaultAddress = scheme + window.location.host + '/echo';
85
86 addressBox = document.getElementById('address');
87 logBox = document.getElementById('log');
88 messageBox = document.getElementById('message');
89
90 addressBox.value = defaultAddress;
91}
92</script>
93</head>
94<body onload="init()">
95
96<form action="#" onsubmit="connect(); return false;">
97<input type="text" id="address" size="40">
98<input type="submit" value="connect">
99</form>
100
101<textarea id="log" rows="10" cols="40" readonly></textarea>
102
103<form action="#" onsubmit="send(); return false;">
104<input type="text" id="message" size="40">
105<input type="submit" value="send">
106</form>
107
108</body>
109</html>