diff --git a/server/tools/robot/kcpclient/clientnet.js b/server/tools/robot/kcpclient/clientnet.js index 4aee2cc6..6b4b281b 100644 --- a/server/tools/robot/kcpclient/clientnet.js +++ b/server/tools/robot/kcpclient/clientnet.js @@ -25,8 +25,9 @@ class ClientNet { this.kcpObj = new kcp.KCP(123, { 'address': '192.168.100.45', - 'port': 7602 + 'port': 17602 }); + this.kcpObj.stream(1); this.conn = dgram.createSocket('udp4'); this.kcpObj.nodelay(0, 0, 0, 0); @@ -39,7 +40,12 @@ class ClientNet { console.log('client error:' + err); }); this.conn.on('message', (msg, rinfo) => { + console.log('message', msg, msg.length); this.kcpObj.input(msg); + const recv = this.kcpObj.recv(); + if (recv) { + console.log('recv', recv, recv.length); + } }); setInterval(() => { @@ -178,11 +184,12 @@ class ClientNet { const msgBuf = msgType.encode(msg).finish(); let buf = Buffer.alloc(12); - buf.writeUInt32LE(msgBuf.length, 0); - buf.writeUInt16LE(msgId, 4); - buf.writeUInt8('K'.charCodeAt(0), 6); - buf.writeUInt8('S'.charCodeAt(0), 7); - buf.writeInt32LE(0, 8); + buf.writeUInt16LE(msgBuf.length, 0); + buf.writeUInt16LE(msgId, 2); + buf.writeInt32LE(0, 4); + buf.writeUInt8('K'.charCodeAt(0), 8); + buf.writeUInt8('S'.charCodeAt(0), 9); + buf.writeInt16LE(0, 10); const buff = Buffer.concat([buf, msgBuf]); this.kcpObj.send(buff, buff.length);