-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-connection.html
More file actions
79 lines (68 loc) · 2.73 KB
/
test-connection.html
File metadata and controls
79 lines (68 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<html>
<head>
<title>Socket.IO Connection Test</title>
<script src="https://cdn.socket.io/4.7.2/socket.io.min.js"></script>
</head>
<body>
<h1>Socket.IO Connection Test</h1>
<div>
<label>Server URL: <input type="text" id="serverUrl" value="http://localhost:3001" style="width: 400px;"></label>
<button onclick="testConnection()">Test Connection</button>
</div>
<div id="status" style="margin-top: 20px; padding: 10px; border: 1px solid #ccc;">
Status: Not connected
</div>
<div id="logs" style="margin-top: 20px; padding: 10px; background: #f5f5f5; font-family: monospace; white-space: pre-wrap;">
</div>
<script>
let socket = null;
function log(message) {
const logs = document.getElementById('logs');
const timestamp = new Date().toLocaleTimeString();
logs.textContent += `[${timestamp}] ${message}\n`;
}
function updateStatus(message, color) {
const status = document.getElementById('status');
status.textContent = 'Status: ' + message;
status.style.backgroundColor = color;
}
function testConnection() {
const serverUrl = document.getElementById('serverUrl').value;
log(`Attempting to connect to: ${serverUrl}`);
updateStatus('Connecting...', '#ffffcc');
// Disconnect previous socket if any
if (socket) {
socket.disconnect();
}
socket = io(serverUrl, {
transports: ['websocket', 'polling'],
reconnection: true,
reconnectionDelay: 1000,
reconnectionAttempts: 5
});
socket.on('connect', () => {
log(`✓ Connected successfully! Socket ID: ${socket.id}`);
updateStatus('Connected', '#ccffcc');
});
socket.on('connect_error', (error) => {
log(`✗ Connection error: ${error.message}`);
updateStatus('Connection failed', '#ffcccc');
});
socket.on('disconnect', (reason) => {
log(`✗ Disconnected: ${reason}`);
updateStatus('Disconnected', '#ffcccc');
});
socket.on('error', (error) => {
log(`✗ Socket error: ${error}`);
});
}
// Auto-fill with production URL if available
window.addEventListener('load', () => {
// You can update this with your Render URL for quick testing
const productionUrl = 'https://your-service.onrender.com';
document.getElementById('serverUrl').placeholder = productionUrl;
});
</script>
</body>
</html>