From cb37f0db7642475eaddb49359c8a23ace70a02ce Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 18 Apr 2023 13:29:46 +0800 Subject: [PATCH] 1 --- server/tools/robot/kcpclient/clientnet.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/server/tools/robot/kcpclient/clientnet.js b/server/tools/robot/kcpclient/clientnet.js index 2b450862..4aee2cc6 100644 --- a/server/tools/robot/kcpclient/clientnet.js +++ b/server/tools/robot/kcpclient/clientnet.js @@ -2,6 +2,8 @@ const protobuf = require('protobufjs'); const kcp = require('./node_modules/node-kcp/build/Release/kcp'); const dgram = require('dgram'); +const update_interval = 200; + function prettyJsonEncode(obj) { return JSON.stringify(obj, "", " "); } @@ -29,6 +31,7 @@ class ClientNet { this.kcpObj.nodelay(0, 0, 0, 0); this.kcpObj.output((data, size, context) => { + console.log('kcp output', data, size, context); this.conn.send(data, 0, size, context.port, context.address); }); @@ -38,6 +41,11 @@ class ClientNet { this.conn.on('message', (msg, rinfo) => { this.kcpObj.input(msg); }); + + setInterval(() => { + this.kcpObj.update(Date.now()); + }, update_interval); + } selfRegisterMsgHandle(msgName) { @@ -175,8 +183,10 @@ class ClientNet { buf.writeUInt8('K'.charCodeAt(0), 6); buf.writeUInt8('S'.charCodeAt(0), 7); buf.writeInt32LE(0, 8); - //this.conn.sendBinary(Buffer.concat([buf, msgBuf])); - console.log(name, msg, (Buffer.concat([buf, msgBuf])).length); + + const buff = Buffer.concat([buf, msgBuf]); + this.kcpObj.send(buff, buff.length); + console.log(name, msg, buff.length); } }