question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

when the “second api” says it’s similar to the net interface, it means it’s a reliable stream, right? https://github.com/mafintosh/utp-native#socketonconnection-connection

this doesn’t mention how to do NAT hole punching, is there a module for that?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mafintoshcommented, Jun 28, 2016

Yea! You’d basically only use a single utp instance in your entire app. Interesting idea about connecting to the known server using secret-handshake over utp as well. That would work great!

1reaction
mafintoshcommented, Jun 27, 2016

You need a central known server to distribute the external udp port of two peers to the corresponding peers. Here a quick gist of what this could look like.

// server.js
var dgram = require('dgram')
var server = dgram.createSocket('udp4')
var otherRinfo = null

server.on('message', function (message, rinfo) {
  if (otherRinfo) {
    send(otherRinfo, rinfo)
    send(rinfo, otherRinfo)
  }
  otherRinfo = rinfo
})

server.bind(10000)

function send (rinfo, to) {
  var buf = Buffer(JSON.stringify({host: rinfo.address, port: rinfo.port}))
  server.send(buf, 0, buf.length, to.port, to.address)
}

The clients

var utp = require('utp-native')

var socket = utp()

socket.on('message', function (message) {
  // server send us a peer, try and connect
  var otherPeer = JSON.parse(message)
  var connection = socket.connect(otherPeer.port, otherPeer.host)

  connection.write('hello world')
})

// emitted when a new utp connection is established
socket.on('connection', function (connection) {
  console.log('new peer')
  connection.pipe(process.stdout)
})

// send udp message to known-server.com
socket.bind(0, function () {
  socket.send(Buffer('hello'), 0, 5, 10000, 'known-server.com')
})

This is probably the minimum needed for hole punching

Read more comments on GitHub >

github_iconTop Results From Across the Web

33 Synonyms of CLARIFICATIONS - Merriam-Webster
Synonyms for CLARIFICATIONS: explanations, interpretations, illustrations, elucidations, translations, explications, analyses, definitions, comments, ...
Read more >
CLARIFICATION definition | Cambridge English Dictionary
an explanation or more details that makes something clear or easier to understand: Some further clarification of your position is needed.
Read more >
clarifications - Wiktionary
NounEdit. clarifications f. plural of clarification.
Read more >
13 Synonyms & Antonyms for CLARIFICATION - Thesaurus.com
Find 13 ways to say CLARIFICATION, along with antonyms, related words, and example sentences at Thesaurus.com, the world's most trusted free thesaurus.
Read more >
Clarifications – Odyssey of the Mind
The Clarification System. Our Long-Term Problems are written to provide just enough guidance for teams to solve the problem without limiting ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found