mirror of
https://github.com/Leo501/CocosCreatorTutorial.git
synced 2026-06-03 07:59:39 +08:00
更新ws代码
This commit is contained in:
@@ -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();
|
||||
},
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user