How to use the utp-native.createServer function in utp-native

To help you get started, we’ve selected a few utp-native examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github emilbayes / noise-peer / examples / utp.js View on Github external
var utp = require('utp-native')
var pump = require('pump')
var peer = require('..')

// This example uses UTP as the transport protocol, which is a popular choise
// for data heavy applications and p2p. Otherwise this example is equivalent to
// `tcp.js`

// This is the most basic handshake pattern, yielding a "perfect forward secure"
// connection, but with no authentication (in the cryptographic sense) of either
// peer end.
var server = utp.createServer(function onconnection (rawStream) {
  var sec = peer(rawStream, false)

  pump(sec, sec, function (err) {
    if (err) throw err
  })
})

server.listen(function () {
  var port = server.address().port

  var clientRawStream = utp.connect(port)
  var clientSec = peer(clientRawStream, true)

  clientSec.on('data', function (data) {
    console.log(data.toString())
  })
github gridcontrol / gridcontrol / research / utp.js View on Github external
var utp = require('utp-native')

var server = utp.createServer(function (socket) {
  socket.pipe(socket) // echo server
})

server.listen(10000, function () {
  var socket = utp.connect(10000)

  socket.write('hello world')
  socket.on('data', function (data) {
    console.log('echo: ' + data)
  })
})

utp-native

Native bindings for libutp

MIT
Latest version published 3 years ago

Package Health Score

54 / 100
Full package analysis

Popular utp-native functions

Similar packages