2019-04-05 09:54:26 +08:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<pre id="log"></pre>
|
|
|
|
<script>
|
|
|
|
// helper function: log message to screen
|
|
|
|
function log(msg) {
|
|
|
|
document.getElementById('log').textContent += msg + '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
// setup websocket with callbacks
|
|
|
|
var ws = new WebSocket("ws://127.0.0.1:8848/chat");
|
|
|
|
ws.onopen = function() {
|
|
|
|
log('CONNECT');
|
|
|
|
ws.send("hello!!!");
|
|
|
|
};
|
|
|
|
ws.onclose = function() {
|
|
|
|
log('DISCONNECT');
|
|
|
|
};
|
|
|
|
ws.onmessage = function(event) {
|
|
|
|
log('MESSAGE: ' + event.data);
|
2020-11-14 11:48:40 +08:00
|
|
|
// ws.send(event.data);
|
|
|
|
// ws.send(event.data);
|
2019-04-05 09:54:26 +08:00
|
|
|
};
|
|
|
|
</script>
|