Welcome
Awesome Dat
Dat Applications
datproject/dat
datproject/dat-desktop
Community Applications
codeforscience/sciencefair
mafintosh/hyperirc
jondashkyle/soundcloud-archiver
mafintosh/hypervision
joehand/hypertweet
beakerbrowser/dat-photos-app
High-Level APIs
datproject/dat-node
datproject/dat-js
beakerbrowser/pauls-dat-api
beakerbrowser/node-dat-archive
Hosting & Dat Management
mafintosh/hypercore-archiver
datprotocol/hypercloud
beakerbrowser/hashbase
joehand/dat-now
mafintosh/hypercore-archiver-bot
joehand/hypercore-archiver-ws
datproject/dat-registry-api
datproject/dat-registry-client
Managing & Aggregating Dats
datproject/multidat
datproject/multidrive
jayrbolton/dat-pki
beakerbrowser/injestdb
Http Hosting
joehand/hyperdrive-http
beakerbrowser/dathttpd
Dat Link Utilties
datprotocol/dat-dns
joehand/dat-link-resolve
pfrazee/parse-dat-url
juliangruber/dat-encoding
Dat Utilities
joehand/dat-log
mafintosh/dat-ls
karissa/hyperhealth
joehand/hyperdrive-network-speed
File Imports & Exports
juliangruber/hyperdrive-import-files
mafintosh/mirror-folder
pfrazee/hyperdrive-staging-area
pfrazee/hyperdrive-to-zip-stream
Hypercore Tools
mafintosh/hyperpipe
Dat Core Modules
mafintosh/hyperdrive
mafintosh/hypercore
CLI Utilities
joehand/dat-doctor
joehand/dat-ignore
joehand/dat-json
Networking
karissa/hyperdiscovery
mafintosh/discovery-swarm
mafintosh/webrtc-swarm
joehand/dat-swarm-defaults
Lower level networking modules
maxogden/discovery-channel
mafintosh/dns-discovery
mafintosh/multicast-dns
webtorrent/bittorrent-dht
mafintosh/utp-native
mafintosh/signalhub
Storage
datproject/dat-storage
datproject/dat-secret-storage
Random Access
juliangruber/abstract-random-access
mafintosh/multi-random-access
mafintosh/random-access-file
mafintosh/random-access-memory
mafintosh/random-access-page-files
datproject/dat-http
substack/random-access-idb
Other Related Dat Project Modules
mafintosh/peer-network
mafintosh/hyperdht
Dat Project Organization Stuff
datproject/datproject.org
datproject/discussions
datproject/design
datproject/dat-elements
kriesse/dat-colors
kriesse/dat-icons
juliangruber/dat.json
Outdated
juliangruber/dat.haus
poga/hyperfeed
yoshuawuyts/normcore
yoshuawuyts/github-to-hypercore
poga/hyperspark
juliangruber/hypercore-index
juliangruber/hyperdrive-encoding
mafintosh/hyperdrive-http-server
joehand/hyperdrive-http
joehand/dat-push
joehand/dat-backup
joehand/archiver-server
joehand/archiver-api
poga/hyperdrive-ln
substack/hyperdrive-multiwriter
substack/hyperdrive-named-archives
substack/git-dat
CfABrigadePhiladelphia/jawn
maxogden/dat-archiver
juliangruber/hyperdrive-stats
karissa/hypercore-stats-server
mafintosh/hypercore-stats-ui
karissa/zip-to-hyperdrive
joehand/url-dat
joehand/tar-dat
joehand/hyperdrive-duplicate

utp-native

Native bindings for libutp. For more information about utp read BEP 29.

npm install utp-native

build status build status js-standard-style

Usage

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)
  })
})

API

There two APIs available. One that mimicks the net core module in Node as much as possible and another one that allows you to reuse the same udp socket for both the client and server. The last one is useful if you plan on using this in combination with NAT hole punching.

net-like API

server = utp.createServer([onconnection])

Create a new utp server instance.

server.listen([port], [address], [onlistening])

Listen for on port. If you don't provide a port or pass in 0 a free port will be used. Optionally you can provide an interface address as well, defaults to 0.0.0.0.

var addr = server.address()

Returns an address object, {port, address} that tell you which port / address this server is bound to.

server.on('listening')

Emitted when the server is listening

server.on('connection', connection)

Emitted when a client has connected to this server

server.on('error', err)

Emitted when a critical error happened

server.close()

Closes the server.

server.on('close')

Emitted when the server is fully closed. Note that this will only happen after all connections to the server are closed.

server.maxConnections

Set this property is you want to limit the max amount of connections you want to receive

server.connections

An array of all the connections the server has.

server.ref()

Opposite of unref.

server.unref()

Unreferences the server from the node event loop.

connection = utp.connect(port, [host])

Create a new client connection. host defaults to localhost. The client connection is a duplex stream that you can write / read from.

address = connection.address()

Similar to server.address.

connection.ref()

Similar to server.ref()

connection.unref()

Similar to server.unref()

connection.on('close')

Emitted when the connection is fully closed.

connection.on('error', err)

Emitted if an unexpected error happens.

connection.destroy()

Forcefully destroys the connection.

In addition to this the connection has all the classic stream methods such as .write etc.

Socket API

The socket api allows you to reuse the same underlying UDP socket to both connect to other clients on accept incoming connections. It also mimicks the node core dgram socket api.

socket = utp()

Create a new utp socket

socket.bind([port], [host], [onlistening])

Bind the socket.

socket.on('listening')

Emitted when the socket is bound.

socket.send(buf, offset, len, port, host, [callback])

Send a udp message.

socket.on('message', buffer, rinfo)

Listen for a udp message.

socket.close()

Close the socket.

address = socket.address()

Returns an address object, {port, address} that tell you which port / address this socket is bound to.

socket.on('close')

Emitted when the socket is fully closed.

socket.on('error')

Emitted if the socket experiences an error.

socket.listen([port], [host], [onlistening])

Start listening for incoming connections. Performs a bind as well.

socket.on('connection', connection)

Emitted after you start listening and a client connects to this socket. Connection is similar to the connection used in the net api.

connection = socket.connect(port, host)

Connect to another socket. Connection is similar to the connection used in the net api.

socket.unref()

Dereference the socket from the node event loop.

socket.ref()

Opposite of socket.unref()

License

MIT