更新ws代码

This commit is contained in:
我是leo
2018-07-29 23:18:50 +08:00
parent 5a86b6bf20
commit c5adcda031
6 changed files with 522 additions and 103 deletions

View File

@@ -1,6 +1,7 @@
const net = require('net');
const Emitter = require('./Emitter');
const emitter = new Emitter();
const wsNet = require('./WsNet');
cc.Class({
extends: cc.Component,
@@ -17,17 +18,29 @@ cc.Class({
onLoad: function () {
this.label.string = this.text;
this.net = net;
this.net.connect();
this.net.addHandler('test_pust', (data) => {
console.log('test_pust', data);
// this.net = net;
// this.net.connect();
// this.net.addHandler('test_pust', (data) => {
// console.log('test_pust', data);
// });
// this.net.send('test_pust', 'hello');
// emitter.on('test_1', this.onTest_1, this);
// emitter.on('test_2', this.onTest_2);
// emitter.emit('test_1', 1, 1, 1);
// emitter.emit('test_2', 1, 1, 1);
// emitter.off('test_1', this.onTest_1);
this.initWsNet();
},
initWsNet() {
wsNet.init('ws://192.168.2.176:8181', (result) => {
console.log('result=', result);
});
this.net.send('test_pust', 'hello');
emitter.on('test_1', this.onTest_1, this);
emitter.on('test_2', this.onTest_2);
emitter.emit('test_1', 1, 1, 1);
emitter.emit('test_2', 1, 1, 1);
emitter.off('test_1', this.onTest_1);
},
onEventClick_close() {
wsNet.close();
},