Skip to content

Instantly share code, notes, and snippets.

@WietseWind
Created March 8, 2018 00:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save WietseWind/1016710c39ff512c645bf9affc512abe to your computer and use it in GitHub Desktop.
Save WietseWind/1016710c39ff512c645bf9affc512abe to your computer and use it in GitHub Desktop.
Rippled Websocket proxy to test reconnecting & health checking for https://www.npmjs.com/package/rippled-ws-client
const WebSocket = require('ws')
const ws = new WebSocket('wss://s1.ripple.com')
const wss = new WebSocket.Server({ port: 8011 })
wss.on('connection', function connection(c) {
let sendmessages = true
setTimeout(function () {
sendmessages = false
}, 20 * 1000)
c.on('message', function incoming(message) {
console.log('> %s', message)
if (sendmessages) ws.send(message)
})
c.on('close', function closed(r) {
console.log('close', r)
})
ws.on('message', function message(m) {
console.log('< %s', m)
c.send(m)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment