1
This commit is contained in:
parent
943fd1415c
commit
55516aee64
@ -1,5 +1,6 @@
|
|||||||
const protobuf = require('protobufjs');
|
const protobuf = require('protobufjs');
|
||||||
const ws = require('nodejs-websocket');
|
var kcp = require('node-kcp');
|
||||||
|
const dgram = require('dgram');
|
||||||
|
|
||||||
function prettyJsonEncode(obj) {
|
function prettyJsonEncode(obj) {
|
||||||
return JSON.stringify(obj, "", " ");
|
return JSON.stringify(obj, "", " ");
|
||||||
@ -19,6 +20,25 @@ class ClientNet {
|
|||||||
this.recvBuf = Buffer.alloc(0);
|
this.recvBuf = Buffer.alloc(0);
|
||||||
this.uniqId = 1000;
|
this.uniqId = 1000;
|
||||||
this.msgHandlerMap = new Map();
|
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) {
|
selfRegisterMsgHandle(msgName) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user