This commit is contained in:
aozhiwei 2023-04-18 13:23:40 +08:00
parent f6f0e5a6bf
commit c79b8453a9
2 changed files with 10 additions and 14 deletions

View File

@ -1,6 +1,5 @@
const protobuf = require('protobufjs');
var kcp = require('./node_modules/node-kcp/build/Release/kcp');
//var kcp = require('node-kcp');
const kcp = require('./node_modules/node-kcp/build/Release/kcp');
const dgram = require('dgram');
function prettyJsonEncode(obj) {
@ -21,7 +20,6 @@ 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',
@ -73,8 +71,8 @@ class ClientNet {
}
async connect() {
this.conn = await ws.connect(this.url);
this.on('binary', this.#onReceive.bind(this));
//this.conn = await ws.connect(this.url);
//this.on('binary', this.#onReceive.bind(this));
}
on(eventName, ...args) {
@ -177,7 +175,7 @@ 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]));
//this.conn.sendBinary(Buffer.concat([buf, msgBuf]));
console.log(name, msg, (Buffer.concat([buf, msgBuf])).length);
}

View File

@ -77,14 +77,12 @@ class TestCase {
async step2() {
await this.gameConn.init();
await this.gameConn.connect();
this.gameConn.on('connect', () => {
console.log('relation onConnect');
this.gameConn.accountId = this.loginData['account_id'];
this.gameConn.sessionId = this.loginData['session_id'];
this.gameConn.sendMsg('CMLogin', {
account_id: this.loginData['account_id'],
session_id: this.loginData['session_id'],
});
this.gameConn.accountId = this.loginData['account_id'];
this.gameConn.sessionId = this.loginData['session_id'];
this.gameConn.sendMsg('CMJoin', {
account_id: this.loginData['account_id'],
session_id: this.loginData['session_id'],
});
}