mafintosh/duplex-json-stream

语言: JavaScript

git: https://github.com/mafintosh/duplex-json-stream

将传输流转换为从/ serializes到json解析的双工流
Turn a transport stream into a duplex stream that parses from / serializes to json
README.md (中文)

双面JSON-流

将传输流转换为从/ serializes到json解析的双工流

npm install duplex-json-stream

build status

用法

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

执照

WITH

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

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