23 lines
586 B
HTML
23 lines
586 B
HTML
<!-- websockets.html -->
|
|
<input id="input" type="text" />
|
|
<button onclick="send()">Send</button>
|
|
<pre id="output"></pre>
|
|
<script>
|
|
var input = document.getElementById("input");
|
|
var output = document.getElementById("output");
|
|
var socket = new WebSocket("ws://localhost:8080/echo");
|
|
|
|
socket.onopen = function () {
|
|
output.innerHTML += "Status: Connected\n";
|
|
};
|
|
|
|
socket.onmessage = function (e) {
|
|
output.innerHTML += "Server: " + e.data + "\n";
|
|
};
|
|
|
|
function send() {
|
|
socket.send(input.value);
|
|
input.value = "";
|
|
}
|
|
</script>
|