cocosCreator webSocket工具
const webSocketHelper = cc.Class({ extends: cc.Component, createWs(){ this.ws = new WebSocket("ws://127.0.0.1:8888"); this.ws.onopen = function (event) { console.log("已连接."); }.bind(this); this.ws.onmessage = function (event) { let data = JSON.parse(event.data); console.log("收到消息: " + event.data); }.bind(this); this.ws.onerror = function (event) { console.log("发生错误"); }.bind(this); this.ws.onclose = function (event) { console.log("已关闭"); }.bind(this); }, send(msg){ this.ws.send(msg); } }); window.webSocketHelper = new webSocketHelper();
相关推荐
guozewei0 2020-03-06
jonychen 2020-04-22
honeyth 2020-09-13
mjshldcsd 2020-08-15
Ping 2020-08-15
Kakoola 2020-08-01
Yellowpython 2020-08-01
chenguangchun 2020-07-26
dailinqing 2020-07-18
xiaouncle 2020-07-05
delmarks 2020-06-28
MayerF 2020-06-14
MrHaoNan 2020-06-13
smalllove 2020-06-09
JayFighting 2020-06-08
xiaoge00 2020-06-07
haokele 2020-05-31
matthewhan 2020-05-25