cocosCreator webSocket工具
Posted jianxiaopo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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();
以上是关于cocosCreator webSocket工具的主要内容,如果未能解决你的问题,请参考以下文章
学习cocoscreator 接触到的WebSocket的学习笔记
一起来学习用nodejs和CocosCreator开发网络游戏吧--- 云服务器的搭建
netty : websocketx.WebSocketHandshakeException: not a WebSocket handshake request: missing upgrade(代