diff --git a/server/tools/robot/kcpclient/clientnet.js b/server/tools/robot/kcpclient/clientnet.js index d82ebcba..b649bdf0 100644 --- a/server/tools/robot/kcpclient/clientnet.js +++ b/server/tools/robot/kcpclient/clientnet.js @@ -1,5 +1,6 @@ - const protobuf = require('protobufjs'); -const ws = require('nodejs-websocket'); +const protobuf = require('protobufjs'); +var kcp = require('node-kcp'); +const dgram = require('dgram'); function prettyJsonEncode(obj) { return JSON.stringify(obj, "", " "); @@ -19,6 +20,25 @@ class ClientNet { this.recvBuf = Buffer.alloc(0); this.uniqId = 1000; this.msgHandlerMap = new Map(); + console.log(kcp); + this.kcpObj = new kcp.KCP(123, + { + 'address': '192.168.100.45', + 'port': 7602 + }); + this.conn = dgram.createSocket('udp4'); + + this.kcpObj.nodelay(0, 0, 0, 0); + this.kcpObj.output((data, size, context) => { + this.conn.send(data, 0, size, context.port, context.address); + }); + + this.conn.on('error', (err) => { + console.log('client error:' + err); + }); + this.conn.on('message', (msg, rinfo) => { + this.kcpObj.input(msg); + }); } selfRegisterMsgHandle(msgName) {