This commit is contained in:
aozhiwei 2023-04-17 20:29:32 +08:00
parent 943fd1415c
commit 55516aee64

View File

@ -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) {