Front-end/vue/websocket.html

27 lines
799 B
HTML
Raw Permalink Normal View History

2023-10-19 02:19:45 -04:00
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebSocket</title>
</head>
<body>
<script>
var ws = new WebSocket("ws://192.168.60.109:8081/socket/123");
ws.onopen = function() {
document.write('<span>ws: ' + ws.url + ' opened</span><br/>');
ws.send('Hello, websocket!');
};
ws.onmessage = function(evt) {
document.write('<span>ws: '+ evt.data + '</span><br/>');
};
ws.onclose = function(evt) {
document.write('<span font="yellow">ws: closed</span><br/>');
console.log(evt);
};
ws.onerror = function(evt) {
document.write('<span font="darkred">ws: closed</span><br/>');
console.log(evt);
};
</script>
</body>
</html>