-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_websocket.js
More file actions
45 lines (35 loc) · 1.11 KB
/
test_websocket.js
File metadata and controls
45 lines (35 loc) · 1.11 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
const WebSocket = require('ws');
console.log('Testing WebSocket connection to ws://localhost:8080/ws');
const ws = new WebSocket('ws://localhost:8080/ws');
ws.on('open', function open() {
console.log('✅ WebSocket connected successfully!');
// Send a subscription message
const subscribeMessage = {
action: 'subscribe',
subscription: {
type: 'all_transactions'
}
};
console.log('📤 Sending subscription:', JSON.stringify(subscribeMessage));
ws.send(JSON.stringify(subscribeMessage));
// Close after 5 seconds
setTimeout(() => {
console.log('🔌 Closing connection...');
ws.close();
}, 5000);
});
ws.on('message', function message(data) {
console.log('📥 Received:', data.toString());
});
ws.on('error', function error(err) {
console.error('❌ WebSocket error:', err.message);
});
ws.on('close', function close() {
console.log('🔌 WebSocket connection closed');
process.exit(0);
});
// Timeout after 10 seconds
setTimeout(() => {
console.error('⏰ Connection timeout');
process.exit(1);
}, 10000);