添加websocket使用demo

This commit is contained in:
leo
2018-07-17 00:58:02 +08:00
parent 49d23c9945
commit b7799a0c42
56 changed files with 26154 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
const net = require('net');
const Emitter = require('./Emitter');
const emitter = new Emitter();
cc.Class({
extends: cc.Component,
properties: {
label: {
default: null,
type: cc.Label
},
// defaults, set visually when attaching this script to the Canvas
text: 'Hello, World!'
},
// use this for initialization
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.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);
},
onTest_1(data) {
console.log('onTest_1 data', arguments, this);
},
onTest_2(data) {
console.log('onTest_2 data', data, this);
console.log(arguments);
},
// called every frame
update: function (dt) {
},
});