NodeJsにおけるTCPの粘着パック、パケット分けの高性能ソリューションを共有する.
1528 ワード
最新の更新はgithubをご覧ください.
NodeJsの中でTCPは包んで、分けて解決案を包みます!
NodeJsの中でTCPは包んで、分けて解決案を包みます!
1. TCP
2. 512 , 512 , 512
3.
4.
5. [ ]
6. [ ]
```
```
var Stick = require('./stickPackage');
let stick = new Stick();
// buffer
let bytes3 = Buffer.from([0x00, 0x02, 0x66, 0x66, 0x00, 0x04, 0x88, 0x02, 0x11, 0x11]);
// buffer ,
let bytes4 = Buffer.from([0x00, 0x02, 0x66, 0x66, 0x00, 0x04, 0x88, 0x02, 0x11]);
let bytes5 = Buffer.from([0x11]);
// buffer , 512
let bytes6 = Buffer.from([0x01, 0xfe]);
let bytes7 = Buffer.alloc(510).fill(33);
// buffer , 513
let bytes8 = Buffer.from([0x01, 0xff]);
let bytes9 = Buffer.alloc(511).fill(33);
//
stick.onData(function (data) {
console.log('receive data,length:' + data.length);
console.log('receive data,contents:' + JSON.stringify(data));
});
// 10 , 2, 4
console.log('log: , Put[ Put ]');
stick.putData(bytes3);
// 10 , 2, 4 , Put
console.log('log: , Put[ Put ]');
stick.putData(bytes4);
stick.putData(bytes5);
console.log('log: 512 [ ]');
stick.putData(bytes6);
stick.putData(bytes7);
console.log('log: 513 [ ]');
stick.putData(bytes8);
stick.putData(bytes9);
:[ star, watch]
https://github.com/lvgithub/stickPackage.git