6.0.0 • Published 5 years ago

tcp-log-client v6.0.0

Weekly downloads
161
License
MIT
Repository
github
Last release
5 years ago

Stream and write tcp-log-server entries. Reconnect automatically.

var TCPLogClient = require('tcp-log-client')

var client = new TCPLogClient({
  // Use these options for `require('net').connect(options)`.
  server: {port: port},
  // Enable TCP keepalive. Enabled by default.
  keepAlive: true,
  // Disable the Nagle algorithm. Disabled by default.
  noDelay: true,
  // Start reading from entry index 1. 1 by default.
  from: 1,
  // Stop trying to reconnect and fail after 5 attempts.
  reconnect: {failAfter: 5}
})
  .on('error', function (error) {
    console.error(error)
  })
  .on('fail', function () {
    console.error('Failed to reconnect.')
  })
  .once('ready', function () {
    if (client.connected) {
      client.write({example: 'entry'}, function (error, index) {
        console.log('New entry index is %d', index)
        // Permanently disconnect and end `client.readStream`.
        client.destroy()
      })
    }
  })

// Readable stream of log entries.
// Entries added with `client.write()` will be streamed, too.
client.readStream.on('data', function (chunk) {
  console.log(chunk.index)
  console.log(chunk.entry)
})

See also:

6.0.0

5 years ago

5.0.0

8 years ago

4.0.0

8 years ago

3.1.0

8 years ago

3.0.0

8 years ago

2.0.0

8 years ago

1.0.0

8 years ago