All Projects → StarryInternet → missive

StarryInternet / missive

Licence: MIT license
Fast, lightweight library for encoding and decoding JSON messages over streams.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to missive

net-Socket
A minimalist wrapper around System.Net.Sockets.Socket.
Stars: ✭ 21 (+31.25%)
Mutual labels:  socket, stream, tcp
Nettychat
基于Netty+TCP+Protobuf实现的Android IM库,包含Protobuf序列化、TCP拆包与粘包、长连接握手认证、心跳机制、断线重连机制、消息重发机制、读写超时机制、离线消息、线程池等功能。
Stars: ✭ 1,979 (+12268.75%)
Mutual labels:  socket, tcp
Owasp Mth3l3m3nt Framework
OWASP Mth3l3m3nt Framework is a penetration testing aiding tool and exploitation framework. It fosters a principle of attack the web using the web as well as pentest on the go through its responsive interface.
Stars: ✭ 139 (+768.75%)
Mutual labels:  socket, stream
Zserver4d
ZServer4D 是一套从商业项目剥离而出的云服务器中间件,可以承载百万级的分布式负载服务,并且支持IoT及内网穿透
Stars: ✭ 199 (+1143.75%)
Mutual labels:  socket, tcp
Async Sockets Cpp
Simple thread-based asynchronous TCP & UDP Socket classes in C++.
Stars: ✭ 127 (+693.75%)
Mutual labels:  socket, tcp
Socketpushclient
最近项目中要求做推送,基于内网的。由于工期不是很紧,需求不是很严格,所以放弃了使用三方的推送框架,基于Socket自己写了消息推送功能(服务端+android端)。服务器端使用java,客户端使用Android。本人是做Android开发的,所以demo重点介绍客户端的一些代码,包括Socket的TCP长连接及发消息,Service如何不被轻易杀死,通过aidl实现界面实时与Service的通信,可以在界面上控制Socket的连接与断开以及发消息,并采用了Parcelable对象实现aidl传参
Stars: ✭ 129 (+706.25%)
Mutual labels:  socket, tcp
Iot Dc3
IOT DC3 is an open source, distributed Internet of Things (IOT) platform based on Spring Cloud. It is used for rapid development of IOT projects and management of IOT devices. It is a set of solutions for IOT system.
Stars: ✭ 195 (+1118.75%)
Mutual labels:  socket, tcp
Goproxy
🔥 Proxy is a high performance HTTP(S) proxies, SOCKS5 proxies,WEBSOCKET, TCP, UDP proxy server implemented by golang. Now, it supports chain-style proxies,nat forwarding in different lan,TCP/UDP port forwarding, SSH forwarding.Proxy是golang实现的高性能http,https,websocket,tcp,socks5代理服务器,支持内网穿透,链式代理,通讯加密,智能HTTP,SOCKS5代理,黑白名单,限速,限流量,限连接数,跨平台,KCP支持,认证API。
Stars: ✭ 11,334 (+70737.5%)
Mutual labels:  socket, tcp
Ohsce
PHP HI-REL SOCKET TCP/UDP/ICMP/Serial .高可靠性PHP通信&控制框架SOCKET-TCP/UDP/ICMP/硬件Serial-RS232/RS422/RS485 AND MORE!
Stars: ✭ 206 (+1187.5%)
Mutual labels:  socket, tcp
Tcpprobe
Modern TCP tool and service for network performance observability.
Stars: ✭ 207 (+1193.75%)
Mutual labels:  socket, tcp
Pypacker
📦 The fastest and simplest packet manipulation lib for Python
Stars: ✭ 216 (+1250%)
Mutual labels:  socket, tcp
Socket
Non-blocking socket and TLS functionality for PHP based on Amp.
Stars: ✭ 122 (+662.5%)
Mutual labels:  socket, tcp
Go Netstat
A netstat implementation written in Go
Stars: ✭ 121 (+656.25%)
Mutual labels:  socket, tcp
Jstp
Fast RPC for browser and Node.js based on TCP, WebSocket, and MDSF
Stars: ✭ 132 (+725%)
Mutual labels:  socket, tcp
Tcpdog
eBPF based TCP observability.
Stars: ✭ 119 (+643.75%)
Mutual labels:  socket, tcp
Kalm.js
The socket manager
Stars: ✭ 155 (+868.75%)
Mutual labels:  socket, tcp
Ssokit Qmake
A Simple & Strong Tool for TCP&UDP Debug
Stars: ✭ 231 (+1343.75%)
Mutual labels:  socket, tcp
Smux
smux is a socket multiplexer written in Golang. It provides fast communication by efficiently a single connection.
Stars: ✭ 97 (+506.25%)
Mutual labels:  socket, tcp
Deta cache
缓存cache服务器
Stars: ✭ 106 (+562.5%)
Mutual labels:  socket, tcp
Oksocket
An blocking socket client for Android applications.
Stars: ✭ 2,359 (+14643.75%)
Mutual labels:  socket, tcp

missive

Build Status

Fast, lightweight library for encoding and decoding JSON messages over streams.

Built using fringe

Installing

npm install --save missive

How it works

Rather than simply using newlines to delimit messages, missive uses the time-honored tradition of length prefixing. We think this is safer, and it can also be quite a bit faster.

Examples

Piping data

missive exports just two functions, encode() and parse(). Each returns an instance of Stream.Transform.

Both streams pipe Buffer instances on the way out (like pretty much all streams), but encode expects an object to be passed to write.

let missive = require('missive');
// create an encoder stream
let encode = missive.encode();
// create a parser stream
let parse = missive.parse();

encode.pipe( parse ).pipe( process.stdout );

encode.write({ hello: 'world' }); // should log {"hello": "world"}
data events

Both streams implement standard data events, which emit Buffer instances.

let missive = require('missive');
let encode = missive.encode();
let parse = missive.parse();

parse.on( 'data', buffer => {
  console.log( buffer instanceof Buffer ); // true
});

encode.write({ foo: 'bar' });
message event

The parse stream also implements a custom message event for convenience. Rather than emitting a Buffer instance, the message event emits a parsed JavaScript object.

let missive = require('missive');
let encode = missive.encode();
let parse = missive.parse();

parse.on( 'message', obj => {
  console.log( obj.foo ); // 'bar'
});

encode.write({ foo: 'bar' });
Writing to sockets
let net = require('net');
let missive = require('missive');
let server = net.createServer();

server.listen( 1337 );

server.on( 'connection', socket => {
  let encode = missive.encode();
  encode.pipe( socket );
  encode.write({ hello: 'world' });
});
Reading from sockets
let net = require('net');
let missive = require('missive');
let client = net.createConnection({ port: 1337 });

client.pipe( missive.parse() ).on( 'message', obj => {
  console.log( obj ); // { hello: 'world' }
});
Compression

To enable Node's zlib compression, instantiate an encode stream with { deflate: true } and a parse stream with { inflate: true }

Note that this will incur a fairly substantial performance penalty, so compression is only advised in situations where message volume is low and saving bytes over the wire is critical.

let missive = require('missive');
let encode = missive.encode({ deflate: true });
let parse = missive.parse({ inflate: true });

parse.on( 'message', obj => {
  console.log( obj.foo ); // 'bar'
});

encode.write({ foo: 'bar' });

Spec

In case you can't use missive on one side of a socket, this is how it encodes data:

  1. Let data be the result of JSON.stringify( object ) + '\n'.
  2. Let header be the string 'JSON' as a utf-8 string.
  3. Let byteLength be the byte length of data as utf-8.
  4. Let buffer be a new buffer of length byteLength + 8.
  5. Write header at byte offset 0 of buffer as a UInt32LE.
  6. Write byteLength at byte offset 4 of buffer as a UInt32LE.
  7. Write data at byte offset 8 of buffer as a utf-8 string.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].