Skip to content

Commit 30c6f0e

Browse files
committed
Updated default port to match the currently public replay
Signed-off-by: Robert Gogete <gogeterobert@yahoo.com>
1 parent ac4bb95 commit 30c6f0e

File tree

3 files changed

+197
-2
lines changed

3 files changed

+197
-2
lines changed

examples/bob.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// bob.js - Bob's client on a different machine
2+
const Gun = require('gun');
3+
require('gun/sea');
4+
const readline = require('readline');
5+
6+
// Connect to remote relay
7+
const gun = Gun({
8+
peers: ['http://nostalgiagame.go.ro:30878/gun']
9+
});
10+
11+
// Create readline interface for chat
12+
const rl = readline.createInterface({
13+
input: process.stdin,
14+
output: process.stdout
15+
});
16+
17+
// Reference to the chat room
18+
const chat = gun.get('chatroom');
19+
20+
// Bob's user info
21+
const bob = {
22+
name: 'Bob',
23+
id: Gun.text.random()
24+
};
25+
26+
console.log('=== Bob\'s Chat Client ===');
27+
console.log('Connected to relay at nostalgiagame.go.ro:30878');
28+
console.log('Your ID:', bob.id);
29+
console.log('Type messages and press Enter to send');
30+
console.log('Type "exit" to quit\n');
31+
32+
// Listen for messages
33+
chat.map().on((message, id) => {
34+
if (message && message.text && message.sender && message.timestamp) {
35+
// Don't show our own messages again
36+
if (message.senderId !== bob.id) {
37+
const time = new Date(message.timestamp).toLocaleTimeString();
38+
console.log(`\n[${time}] ${message.sender}: ${message.text}`);
39+
rl.prompt();
40+
}
41+
}
42+
});
43+
44+
// Function to send message
45+
function sendMessage(text) {
46+
const message = {
47+
text: text,
48+
sender: bob.name,
49+
senderId: bob.id,
50+
timestamp: Date.now()
51+
};
52+
53+
// Put message in the chat
54+
chat.get(Gun.text.random()).put(message);
55+
console.log(`You: ${text}`);
56+
}
57+
58+
// Handle user input
59+
rl.on('line', (input) => {
60+
input = input.trim();
61+
62+
if (input.toLowerCase() === 'exit') {
63+
console.log('Goodbye!');
64+
process.exit();
65+
} else if (input) {
66+
sendMessage(input);
67+
}
68+
69+
rl.prompt();
70+
});
71+
72+
// Initial prompt
73+
rl.setPrompt('> ');
74+
rl.prompt();
75+
76+
// Handle graceful shutdown
77+
process.on('SIGINT', () => {
78+
console.log('\nDisconnecting...');
79+
process.exit();
80+
});

examples/test-client-improved.js

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// Manual Gun.js data query tool using proper WebSocket connections
2+
import Gun from 'gun';
3+
4+
async function queryGunData() {
5+
console.log('🔍 Manual Gun.js WebSocket Query Tool');
6+
console.log('━'.repeat(50));
7+
8+
// Initialize Gun.js with your relay (using the correct port)
9+
const gun = Gun({
10+
peers: ['http://nostalgiagame.go.ro:30878/gun'], // Using port 30878 like your relay
11+
retry: 1000,
12+
timeout: 15000,
13+
localStorage: false // Disable to avoid local cache interference
14+
});
15+
16+
console.log('🔗 Connecting to Gun.js relay: http://nostalgiagame.go.ro:30878/gun');
17+
console.log('⏳ Waiting for WebSocket connection to establish...\n');
18+
19+
// Wait for connection to establish
20+
await new Promise(resolve => setTimeout(resolve, 3000));
21+
22+
return new Promise((resolve) => {
23+
let hasReceivedData = false;
24+
25+
// Set a timeout to resolve if no data is received
26+
const timeout = setTimeout(() => {
27+
if (!hasReceivedData) {
28+
console.log('⏰ Timeout reached - no data received from Gun.js');
29+
console.log('This could mean:');
30+
console.log(' • The relay is not accessible');
31+
console.log(' • No data exists in the namespace');
32+
console.log(' • Network/firewall issues');
33+
resolve();
34+
}
35+
}, 10000);
36+
37+
// Query the namespace root
38+
console.log('📊 Querying namespace root: dig-nat-tools-test');
39+
gun.get('dig-nat-tools-test').once((data) => {
40+
hasReceivedData = true;
41+
clearTimeout(timeout);
42+
43+
console.log('📋 Namespace root data received:');
44+
console.log(' Raw data:', JSON.stringify(data, null, 2));
45+
46+
if (data) {
47+
const keys = Object.keys(data).filter(key => key !== '_');
48+
console.log(' Keys (excluding Gun.js metadata):', keys);
49+
50+
if (keys.includes('hosts')) {
51+
console.log('\n🏠 Found hosts key! Querying hosts data...');
52+
53+
// Query hosts data
54+
gun.get('dig-nat-tools-test').get('hosts').once((hostsData) => {
55+
console.log('📋 Hosts data received:');
56+
console.log(' Raw hosts data:', JSON.stringify(hostsData, null, 2));
57+
58+
if (hostsData) {
59+
const hostKeys = Object.keys(hostsData).filter(key => key !== '_');
60+
console.log(' Host keys:', hostKeys);
61+
62+
// Query each individual host
63+
let processedHosts = 0;
64+
hostKeys.forEach((hostKey, index) => {
65+
console.log(`\n🔍 Querying individual host: ${hostKey}`);
66+
67+
gun.get('dig-nat-tools-test').get('hosts').get(hostKey).once((hostData) => {
68+
console.log(`📄 Host ${hostKey} data:`, JSON.stringify(hostData, null, 2));
69+
70+
processedHosts++;
71+
if (processedHosts === hostKeys.length) {
72+
console.log('\n✅ All hosts processed');
73+
resolve();
74+
}
75+
});
76+
});
77+
78+
if (hostKeys.length === 0) {
79+
console.log('❌ No host keys found in hosts data');
80+
resolve();
81+
}
82+
} else {
83+
console.log('❌ No hosts data received');
84+
resolve();
85+
}
86+
});
87+
} else {
88+
console.log('❌ No "hosts" key found in namespace');
89+
resolve();
90+
}
91+
} else {
92+
console.log('❌ No data received for namespace');
93+
resolve();
94+
}
95+
});
96+
97+
// Also listen for real-time updates
98+
console.log('\n👂 Listening for real-time updates...');
99+
gun.get('dig-nat-tools-test').on((data, key) => {
100+
console.log(`🔔 Real-time update received - Key: ${key}`);
101+
console.log(' Data:', JSON.stringify(data, null, 2));
102+
});
103+
});
104+
}
105+
106+
// Run the query
107+
queryGunData()
108+
.then(() => {
109+
console.log('\n✅ Manual query complete');
110+
process.exit(0);
111+
})
112+
.catch((error) => {
113+
console.error('❌ Error during query:', error);
114+
process.exit(1);
115+
});

examples/test-client.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ async function startClient() {
77

88
// Initialize FileClient with Gun.js configuration
99
const client = new FileClient({
10-
peers: ['http://nostalgiagame.go.ro:30876/gun'], // Connect to deployed relay
10+
peers: ['http://nostalgiagame.go.ro:30878/gun'], // Connect to deployed relay
1111
namespace: 'dig-nat-tools-test', // Use same namespace as host
1212
timeout: 30000 // 30 second timeout
1313
});
1414

1515
try {
16-
console.log('🔗 Connecting to Gun.js relay at http://nostalgiagame.go.ro:30876/gun...');
16+
console.log('🔗 Connecting to Gun.js relay at http://nostalgiagame.go.ro:30878/gun...');
1717
console.log('📡 Using namespace: dig-nat-tools-test');
1818
console.log('🔄 Searching for available peers...');
1919

0 commit comments

Comments
 (0)