Socket
Socket
Sign inDemoInstall

pull-ping

Package Overview
Dependencies
3
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pull-ping

measure latency/rtt and clock skew with pull-streams


Version published
Weekly downloads
37
decreased by-49.32%
Maintainers
1
Install size
93.4 kB
Created
Weekly downloads
 

Readme

Source

pull-ping

have a server and a client ping/pong each other

the server and client are symmetrical. first the client pings the server, then the server pings the client. this means both can measure keep the connection alive, and clock skew correctly, which is sure to be useful at some point.


var ping = require('pull-ping-pong')
var toPull = require('stream-to-pull-stream')

net.createServer(function (stream) {
  stream = toPull.duplex(stream)
  pull(
    stream,
    ping({timeout: 10e3}), //ping every 10 seconds
    stream
  )
}).listen(1234, function () {

  var stream = toPull.duplex(net.connect(1234))

  pull(
    stream,
    //ping every 10 seconds, set 'serve' to true to begin the ping.
    ping({timeout: 10e3, serve: true}),
    stream
  )

  setInterval(function () {
    //check rtt and skew to get statistics about the connection
    console.log(stream.rtt.mean, stream.skew.mean)
  }, 1000)

})

api

ping({timeout: ms, serve: boolean}) => Duplex pull-stream

timeout is the number of milliseconds. the default is 5 minutes, although the first ping will happen immediately.

set serve to true on one side of connection, this starts the ping pong. "serve" is ment in the (table) tennis sense, I set it on the client.

stream.rtt, stream.skew

Statistics on the round trip time and clock skew will be set on the stream object. These are instances of statistics

License

MIT

FAQs

Last updated on 15 Jan 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc