1
This commit is contained in:
parent
cb37f0db76
commit
d6a684dd10
@ -25,8 +25,9 @@ class ClientNet {
|
|||||||
this.kcpObj = new kcp.KCP(123,
|
this.kcpObj = new kcp.KCP(123,
|
||||||
{
|
{
|
||||||
'address': '192.168.100.45',
|
'address': '192.168.100.45',
|
||||||
'port': 7602
|
'port': 17602
|
||||||
});
|
});
|
||||||
|
this.kcpObj.stream(1);
|
||||||
this.conn = dgram.createSocket('udp4');
|
this.conn = dgram.createSocket('udp4');
|
||||||
|
|
||||||
this.kcpObj.nodelay(0, 0, 0, 0);
|
this.kcpObj.nodelay(0, 0, 0, 0);
|
||||||
@ -39,7 +40,12 @@ class ClientNet {
|
|||||||
console.log('client error:' + err);
|
console.log('client error:' + err);
|
||||||
});
|
});
|
||||||
this.conn.on('message', (msg, rinfo) => {
|
this.conn.on('message', (msg, rinfo) => {
|
||||||
|
console.log('message', msg, msg.length);
|
||||||
this.kcpObj.input(msg);
|
this.kcpObj.input(msg);
|
||||||
|
const recv = this.kcpObj.recv();
|
||||||
|
if (recv) {
|
||||||
|
console.log('recv', recv, recv.length);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
@ -178,11 +184,12 @@ class ClientNet {
|
|||||||
|
|
||||||
const msgBuf = msgType.encode(msg).finish();
|
const msgBuf = msgType.encode(msg).finish();
|
||||||
let buf = Buffer.alloc(12);
|
let buf = Buffer.alloc(12);
|
||||||
buf.writeUInt32LE(msgBuf.length, 0);
|
buf.writeUInt16LE(msgBuf.length, 0);
|
||||||
buf.writeUInt16LE(msgId, 4);
|
buf.writeUInt16LE(msgId, 2);
|
||||||
buf.writeUInt8('K'.charCodeAt(0), 6);
|
buf.writeInt32LE(0, 4);
|
||||||
buf.writeUInt8('S'.charCodeAt(0), 7);
|
buf.writeUInt8('K'.charCodeAt(0), 8);
|
||||||
buf.writeInt32LE(0, 8);
|
buf.writeUInt8('S'.charCodeAt(0), 9);
|
||||||
|
buf.writeInt16LE(0, 10);
|
||||||
|
|
||||||
const buff = Buffer.concat([buf, msgBuf]);
|
const buff = Buffer.concat([buf, msgBuf]);
|
||||||
this.kcpObj.send(buff, buff.length);
|
this.kcpObj.send(buff, buff.length);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user