Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.

ping an introducer server, to check that are able to send/receive packets from remote server #36

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions test/src/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,33 @@ test('client ~> server (~500 messages)', async (t) => {
util.promisify(client.close.bind(client))()
])
})

test('can send and receive packets to a remote server', async function (t) {
const server = dgram.createSocket({
type: 'udp4',
reuseAddr: false
})

const client = dgram.createSocket('udp4')

const msg = new Promise((resolve, reject) => {
console.log('start waiting...')
const timer = setTimeout(()=>reject(new Error('no ping back after 3
seconds')), 3_000)
server.on('message', (data)=>{
clearTimeout(timer)
resolve(data)
})
server.on('error', reject)
})

client.send(JSON.stringify({
type: 'ping',
id: crypto.randomBytes(32).toString('hex')
}))

var data = JSON.parse(Buffer.from(await msg))
console.log('received', await msg)
client.close()

})