32 lines
819 B
JavaScript
32 lines
819 B
JavaScript
|
/*
|
||
|
* @Author: giaogiao giaogiao
|
||
|
* @Date: 2023-08-28 11:43:28
|
||
|
* @LastEditors: giaogiao giaogiao
|
||
|
* @LastEditTime: 2023-08-31 17:33:58
|
||
|
* @FilePath: \goweb\app\index.js
|
||
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||
|
*/
|
||
|
var loc = window.location;
|
||
|
var uri = 'ws:';
|
||
|
|
||
|
if (loc.protocol === 'https:') {
|
||
|
uri = 'wss:';
|
||
|
}
|
||
|
uri += '//' + loc.host;
|
||
|
uri += loc.pathname + 'ws';
|
||
|
|
||
|
ws = new WebSocket(uri)
|
||
|
|
||
|
ws.onopen = function() {
|
||
|
console.log('Connected')
|
||
|
}
|
||
|
|
||
|
ws.onmessage = function(evt) {
|
||
|
let date = new Date();
|
||
|
let out = document.getElementById('output');
|
||
|
out.innerHTML = evt.data + "当前时间:"+date.toISOString();
|
||
|
}
|
||
|
|
||
|
// setInterval(function() {
|
||
|
// ws.send('Hello, Server!');
|
||
|
// }, 1000);
|