This repository was archived by the owner on May 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.html
More file actions
136 lines (117 loc) · 4.26 KB
/
test.html
File metadata and controls
136 lines (117 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>WebSocket Test</title>
<script language="javascript" type="text/javascript">
var wsUri;
var output;
function init() {
output = document.getElementById("output");
}
function doOpen(evt) {
wsUri = document.getElementById("wsUri").value;
websocket = new WebSocket(wsUri);
testWebSocket();
}
function testWebSocket() {
websocket.onopen = function (evt) { onOpen(evt) };
websocket.onclose = function (evt) { onClose(evt) };
websocket.onmessage = function (evt) { onMessage(evt) };
websocket.onerror = function (evt) { onError(evt) };
}
function onOpen(evt) {
writeToScreen("CONNECTED");
document.getElementById("connect").disabled = true;
document.getElementById("disconnect").disabled = false;
document.getElementById("sendMessage").disabled = false;
document.getElementById("send").disabled = false;
}
function doClose(evt) {
websocket.close();
}
function onClose(evt) {
writeToScreen("DISCONNECTED");
document.getElementById("connect").disabled = false;
document.getElementById("disconnect").disabled = true;
document.getElementById("sendMessage").disabled = true;
document.getElementById("send").disabled = true;
}
function onMessage(evt) {
writeToScreen('<span style="color: #2196f3;">RESPONSE: ' + evt.data + '</span>');
}
function onError(evt) {
writeToScreen('<span style="color: #ff5722;">ERROR:</span> ' + evt.data);
}
function doSend(message) {
writeToScreen("SENT: " + message);
websocket.send(message);
}
function doSendMessage() {
message = document.getElementById("sendMessage").value;
doSend(message);
}
function writeToScreen(message) {
var pre = document.createElement("p");
pre.style.wordWrap = "break-word";
pre.innerHTML = message;
output.appendChild(pre);
}
function doClear(message) {
output.innerHTML = "";
}
window.addEventListener("load", init, false);
</script>
<style>
html, body {
background-color: #333;
color: #ccc;
}
#echo-config {
float: left;
}
#echo-output {
float: left;
margin-left: 20px;
padding-left: 20px;
width: 350px;
border-left: solid 1px #cccccc;
margin-top: 10px;
}
#output {
border: solid 1px #ccc;
background-color: #222;
padding: 5px;
width: 100%;
height: 172px;
overflow-y: scroll;
}
.echo-button {
margin-top: 5px;
}
</style>
</head>
<body>
<h2>WebSocket Test</h2>
<div id="echo-config">
<strong>Location:</strong><br>
<input class="draw-border" id="wsUri" size="35" value="ws://localhost:8888/">
<br>
<label id="secureCbLabel" style="font-size: smaller;">
Use secure WebSocket (TLS)
<input class="draw-border echo-checkbox" type="checkbox" id="secureCb" onClick="toggleTls();">
</label><br>
<br>
<button class="echo-button" id="connect" onClick="doOpen();">Connect</button>
<button class="echo-button" id="disconnect" disabled="disabled" onClick="doClose();">Disconnect</button>
<br>
<br>
<strong>Message:</strong><br>
<input class="draw-border" id="sendMessage" size="35" disabled="disabled" value="Rock it with HTML5 WebSocket">
<br>
<button class="echo-button" id="send" disabled="disabled" onClick="doSendMessage();">Send</button>
</div>
<div id="echo-output">
<div id="output"></div>
<button class="echo-button" id="clearLogBut" onClick="doClear();">Clear log</button>
</div>
</body>