Simple wrapper for net.Socket to send/receive JSON objects and Buffer streams.
Made as much faster alternative to socket.io + socket.io-stream
Install
$ npm install quick-tcp-socket
Use example
const {
TcpSocket, ReadBufferStream, WriteBufferStream
} = require('quick-tcp-socket');
let clientSocket = net.connect(port, host, () => {
client = new TcpSocket(false, clientSocket);
client.sendPacket("getData1", {
param1: 1,
});
client.once("setData1", (data) => {
});
client.on('close', () => {
client.on('error', (err) => { console.error(err); });
let readStream = fs.createReadStream("file.txt");
client.sendPacketAndStreams("setStream1", {size: 100}, readStream);
});
net.createServer({}, (clientSocket) => {
let client = new TcpSocket(true, clientSocket);
client.on('getData1', (params) => {
client.sendPacket('setData1', {
a: 1, b: 2
});
});
client.on("setStream1", (data) => {
let writeStream = fs.createWriteStream("file.txt");
client.receiveStreams([writeStream], () => {
});
});
client.on('close', () => {
client.on('error', (err) => { console.error(err); });
});
API
todo...