Basic Socket Protocol
install
npm i bsp
Usage
import * as net from "net";
import { send, receive } from "bsp";
var server = net.createServer(socket => {
let temp = [];
socket.on("data", buf => {
for (let msg of receive(buf, temp)) {
}
});
});
server.listen(8000, () => {
var socket = net.createConnection(8000);
socket.on("connect", () => {
socket.write(send("Hello, World!"));
});
});
API
send(...data: any[]): Buffer
receive(buf: Buffer, temp: any[]): IterableIterator<any>
Notice
Due to performance and compatibility considerations, this module (since version
0.2) uses JSON to transfer data instead.
API change in v0.3, passing multiple arguments into send()
now acts exactly
the same as calling send()
multiple times.