Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ukrbublik/quick-tcp-socket
Simple wrapper for net.Socket to send/receive JSON objects and Buffer streams
https://github.com/ukrbublik/quick-tcp-socket
buffer-streams network nodejs socket tcp tcp-socket
Last synced: 26 days ago
JSON representation
Simple wrapper for net.Socket to send/receive JSON objects and Buffer streams
- Host: GitHub
- URL: https://github.com/ukrbublik/quick-tcp-socket
- Owner: ukrbublik
- License: mit
- Created: 2017-01-11T14:10:08.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-05-27T19:13:39.000Z (over 7 years ago)
- Last Synced: 2024-05-02T01:38:49.784Z (7 months ago)
- Topics: buffer-streams, network, nodejs, socket, tcp, tcp-socket
- Language: JavaScript
- Size: 9.77 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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
``` bash
$ npm install quick-tcp-socket
```# Use example
``` jsconst {
TcpSocket, ReadBufferStream, WriteBufferStream
} = require('quick-tcp-socket');//
// Client
//
let clientSocket = net.connect(port, host, () => {
client = new TcpSocket(false, clientSocket);client.sendPacket("getData1", {
param1: 1,
});
client.once("setData1", (data) => {
// data == {a: 1, b: 2}
});client.on('close', () => { /*disconnected*/ });
client.on('error', (err) => { console.error(err); });let readStream = fs.createReadStream("file.txt");
client.sendPacketAndStreams("setStream1", {size: 100}, readStream);
});//
// Server
//
net.createServer({}, (clientSocket) => {
let client = new TcpSocket(true, clientSocket);client.on('getData1', (params) => {
// params.param1 == 1
client.sendPacket('setData1', {
a: 1, b: 2
});
});client.on("setStream1", (data) => {
// data.size == 100
let writeStream = fs.createWriteStream("file.txt");
client.receiveStreams([writeStream], () => {
//stream received
});
});client.on('close', () => { /*client disconnected*/ });
client.on('error', (err) => { console.error(err); });
});
```