1.0.1 • Published 9 years ago

duplex-json-stream v1.0.1

Weekly downloads
11
License
MIT
Repository
github
Last release
9 years ago

duplex-json-stream

Turn a transport stream into an duplex stream that parses from / serializes to json

npm install duplex-json-stream

build status

Usage

var jsonStream = require('duplex-json-stream')
var net = require('net')

var server = net.createServer(function (socket) {
  socket = jsonStream(socket) // turn the transport stream into an object stream
  socket.on('data', function (data) {
    socket.write({echo: data}) // echo back the messages
  })
})

server.listen(10000)

var client = jsonStream(net.connect(10000))

client.write({hello: 'world'})
client.on('data', function (data) {
  console.log(data) // will print {echo: {hello: 'world'}}
})

License

MIT