typescript socket.io

在 typescript 中使用socket.io
方案一: https://forum.cocos.org/u/xff8175

方案二 : 在项目根目录,npm install socket.io-client 和 @types/socket.io-client。

const { ccclass, property } = cc._decorator;

@ccclass
export default class Helloworld extends cc.Component {

@property(cc.Label)
label: cc.Label = null;

@property
text: string = 'hello';

start() {
    // init logic
    let self = this;
    var socket = null;

    console.log("执行 socket")
    socket = io('http://192.168.31.230:2100');
    socket.on('connect', function (msg) {
        self.label.string = "web调试:" + msg;
        console.log("返回信息-------------" + msg);
    });

}

}