Closed raphael10-collab closed 3 years ago
Can you share server.js
This is server.js
:
/ / https://github.com/hypercore-protocol/p2p-multiwriter-with-autobase/tree/main/problems/01
import DHT from '@hyperswarm/dht'
// Make a Hyperswarm DHT node that connects to the global network.
const node = new DHT()
const server = node.createServer(function (encryptedSocket) {
// Called when a new connection arrives.
console.log('New connection from', encryptedSocket.remotePublicKey.toString('hex'))
encryptedSocket.write('Hello world!')
encryptedSocket.end()
})
const keyPair = DHT.keyPair()
await server.listen(keyPair)
// Server is now listening.
console.log('Connect to:')
console.log(keyPair.publicKey.toString('hex'))
I just tried again, without modifying anything ( apart from changing the key's value in client.js
), and it works fine :
(base) raphy@pc:~/hypercore/p2p-multiwriter-with-autobase/solutions/01$ node server.js
Connect to:
2914c849f98e816c2ed2380bc0820c4487ad2b9f4aaa1e62002513d8332962ae
New connection from e16382517194c57e2e8413df14c847578dc57bd62d0e42b23d1430128743fc76
(base) raphy@pc:~/hypercore/p2p-multiwriter-with-autobase/solutions/01$ node client.js
Connected to server
Remote said: Hello world!
client.js
:
// https://github.com/hypercore-protocol/p2p-multiwriter-with-autobase/tree/main/problems/01
import DHT from '@hyperswarm/dht'
const node = new DHT()
const remotePublicKey = Buffer.from('2914c849f98e816c2ed2380bc0820c4487ad2b9f4aaa1e62002513d8332962ae', 'hex')
const encryptedSocket = node.connect(remotePublicKey)
encryptedSocket.on('open', function () {
console.log('Connected to server')
})
encryptedSocket.on('data', function (data) {
console.log('Remote said:', data.toString())
})
Yep works for me also, you prob tried to connect before the listen was done, or a retry was happening due to some fluke
Problem 1:
client.js :
I get this error:
How to solve the issue?