private void SetupService(WebSocketServer server) { server.AddWebSocketService <WsService>("/msf", (service) => { service.IgnoreExtensions = true; service.SetServerSocket(this); var peer = new PeerWsServer(service); service.OnMessageEvent += (data) => { peer.HandleDataReceived(data, 0); }; ExecuteOnUpdate(() => { MsfTimer.Instance.StartCoroutine(peer.SendDelayedMessages(initialSendMessageDelayTime)); OnClientConnectedEvent?.Invoke(peer); }); peer.OnPeerDisconnectedEvent += OnClientDisconnectedEvent; service.OnCloseEvent += reason => { peer.NotifyDisconnectEvent(); }; service.OnErrorEvent += reason => { Logs.Error(reason); peer.NotifyDisconnectEvent(); }; }); server.AddWebSocketService <EchoService>("/echo"); }
/// <summary> /// Triggered when the client is connected to the remote end point. /// </summary> protected void OnConnected() { businessThread = new Thread(BusinessQueue); businessThread.IsBackground = true; businessThread.Start(); OnClientConnectedEvent?.Invoke(); }
/// <summary> /// Triggered when a new client is connected to the server. /// </summary> /// <param name="connection"></param> private void OnClientConnected(NetUser connection) { try { OnClientConnectedEvent?.Invoke(connection); } catch (Exception ex) { Debug(ex.Message + " -- " + ex.StackTrace); } }