Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
If you like, you can subscribe to start or watch
npm i stickpackage
git clone https://github.com/lvgithub/stick.git
npm install
cd example/tcp-buffer/
#in terminal:
node server.js
#in other terminal:
node client.js
#then client will connect to the server and sending data to each other
bufferSize: Setting the size of the cache space
setReadIntBE(type) type:16 short(len:2)
setReadIntBE(type) type:32 int(len:4)
setReadIntLE(type) type:16 short(len:2)
setReadIntLE(type) type:32 int(len:4)
options.bufferSize: Setting the size of the cache space
options.type:Set header length (16|32)
options.bigEndian: The default buffer is false
msgCenter.publish('123')
=> <Buffer 00 03 31 32 33> // 00 03 (data len) 31 32 33 (123)
msgHandleFun:
msgCenter.onMsgRecv(msg => {
console.log(`recv data: ` + msg.toString())
...do something
})
const MsgCenter = require('stickpackage').msgCenter
const msgCenter = new MsgCenter()
msgCenter.onMsgRecv(data => {
console.log(`recv data: ` + data.toString())
})
msgCenter.putData(Buffer.from([0x00, 0x02, 0x31, 0x32, 0x00, 0x04, 0x31, 0x32, 0x33, 0x34]))
//=> recv data: 12
//=> recv data: 1234
const Stick = require('stickpackage').stick;
const stick = new Stick(1024).setReadIntBE('16')
/*
* data1:[0x00, 0x02, 0x66, 0x66]
* data2:[0x00, 0x04, 0x88, 0x02, 0x11, 0x11]
*/
const data = Buffer.from([0x00, 0x02, 0x66, 0x66, 0x00, 0x04, 0x88, 0x02, 0x11, 0x11]);
const data2_1 = Buffer.from([0x00, 0x00, 0x00, 0x02, 0x66, 0x66, 0x00, 0x04, 0x88, 0x02, 0x11]);
const data2_2 = Buffer.from([0x11]);
stick.onData(function (data) {
console.log('receive data,length:' + data.length);
console.log(data)
});
stick.putData(data);
stick.putData(data2_1);
stick.putData(data2_2);
// result:
// receive data,length:4 <Buffer 00 02 66 66>
// receive data,length:6 <Buffer 00 04 88 02 11 11>
// receive data,length:2 <Buffer 00 00> receive data, length:4 < Buffer 00 02 66 66> receive data, length:6< Buffer 00 04 88 02 11 11>
// Client.js
const net = require('net')
const stick = require('../../index')
const msgCenter = new stick.msgCenter()
const client = net.createConnection({
port: 8080,
host: '127.0.0.1'
}, function () {
const msgBuffer = msgCenter.publish('username=123&password=1234567,qwe')
client.write(msgBuffer)
})
client.on('data', function (data) {
console.log(data.toString())
})
client.on('end', function () {
console.log('disconnect from server')
})
// Server.js
const net = require('net')
const stick = require('../../index')
const tcp_server = net.createServer(function (socket) {
const msgCenter = new stick.msgCenter()
socket.on('data', function (data) {
msgCenter.putData(data)
})
msgCenter.onMsgRecv(function (data) {
console.log('recv data: ' + data.toString())
})
socket.on('close', function (error) {
console.log('client disconnected')
})
socket.on('error', function (error) {
console.log(`error: ${error}`)
})
})
tcp_server.on('error', function (err) {
throw err
})
tcp_server.listen(8080, function () {
console.log('tcp_server listening on 8080')
})
// Clinet.js
const net = require('net')
const client = net.createConnection({ port: 8080, host: '127.0.0.1' }, function () {
const body = Buffer.from('username=123&password=1234567,qwe')
const headBuf = new Buffer(4)
headBuf.writeUInt32BE(body.byteLength, 0)
console.log('data length: ' + headBuf.readInt32BE())
client.write(headBuf)
client.write(body)
console.log('data body: ' + body.toString())
})
client.on('data', function (data) {
console.log(data.toString())
})
client.on('end', function () {
console.log('disconnect from server')
})
// Server.js
const net = require('net')
const stick_package = require('../../index').stick
const tcp_server = net.createServer(function (socket) {
socket.stick = new stick_package(1024).setReadIntBE('32')
socket.on('data', function (data) {
socket.stick.putData(data)
})
socket.stick.onData(function (data) {
const head = new Buffer(4)
data.copy(head, 0, 0, 4)
const body = new Buffer(head.readInt32BE())
data.copy(body, 0, 4, head.readInt32BE())
console.log('data length: ' + head.readInt32BE())
console.log('body content: ' + body.toString())
})
socket.on('close', function (error) {
console.log('client disconnected')
})
socket.on('error', function (error) {
console.log(`error: ${error}`)
})
})
tcp_server.on('error', function (err) {
throw err
})
tcp_server.listen(8080, function () {
console.log('tcp_server listening on 8080')
})
Copyright (c) 2017-present, ximen (G.doe)
FAQs
The solution of sticky package problem of TCP for Node.Js !
We found that tcppk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.