需求:
前端使用cocos creater ts开发,websocket连接后端出现onopen不回调,关闭时要回调onclose
如下代码为前端代码:
import { Component, Node, log } from 'cc';
import EventMgr from "../EventMgr";
var State = {
Disconnected: 0, // 断开连接
Connecting: 1, // 正在连接
Connected: 2, // 已经连接;
};
export default class NetMgr extends Component {
public static Instance: NetMgr = null as unknown as NetMgr;
private url: string = null as unknown as string;
private state: number = State.Disconnected;
private sock: WebSocket|null = null as unknown as WebSocket;
onLoad() {
if (NetMgr.Instance === null) {
NetMgr.Instance = this;
}
else {
this.destroy();
return;
}
this.state = State.Disconnected;
}
......
人才:
要求熟悉netty和cocos creater
参考:
辅助解决bug
合作方式:
按次数合作