mirror of
https://github.com/MatrixSeven/file-transfer-go.git
synced 2026-02-22 23:04:45 +08:00
支持多人加入/下载
This commit is contained in:
50
web/static/test-websocket.html
Normal file
50
web/static/test-websocket.html
Normal file
@@ -0,0 +1,50 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>WebSocket连接测试</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>WebSocket连接测试</h1>
|
||||
<div id="status">未连接</div>
|
||||
<button onclick="testConnection()">测试连接</button>
|
||||
<div id="log"></div>
|
||||
|
||||
<script>
|
||||
function log(message) {
|
||||
const logDiv = document.getElementById('log');
|
||||
logDiv.innerHTML += '<div>' + new Date().toLocaleTimeString() + ': ' + message + '</div>';
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
function testConnection() {
|
||||
const code = '354888'; // 使用已存在的房间码
|
||||
const role = 'receiver';
|
||||
const wsUrl = `ws://localhost:8080/ws/p2p?code=${code}&role=${role}`;
|
||||
|
||||
log('尝试连接: ' + wsUrl);
|
||||
|
||||
const ws = new WebSocket(wsUrl);
|
||||
|
||||
ws.onopen = function() {
|
||||
log('WebSocket连接成功!');
|
||||
document.getElementById('status').textContent = '已连接';
|
||||
};
|
||||
|
||||
ws.onerror = function(error) {
|
||||
log('WebSocket错误: ' + JSON.stringify(error));
|
||||
};
|
||||
|
||||
ws.onclose = function(event) {
|
||||
log('WebSocket关闭: 代码=' + event.code + ', 原因=' + event.reason);
|
||||
document.getElementById('status').textContent = '已断开';
|
||||
};
|
||||
|
||||
ws.onmessage = function(event) {
|
||||
log('收到消息: ' + event.data);
|
||||
};
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user