public void Join() { try { _is_running = verification() ? true : throw new Exception($"{Id} is not chat client."); while (IsClientConnected() && _is_running) { if (_stream.DataAvailable) { // десиарелизация сообщения BinaryFormatter formatter = new BinaryFormatter(); ClientMessage newMessage = (ClientMessage)formatter.Deserialize(_stream); ClientOutgoingMessageEvent?.Invoke(this, newMessage); } Thread.Sleep(10); } } catch (Exception ex) { _is_running = false; ClientErrorEvent?.Invoke(this, ex); } finally { _tcp_client?.Close(); ClientDisconnectEvent?.Invoke(this, null); } }
public override void OnClientError(NetworkConnection conn, int errorCode) { Debug.LogFormat("OnClientError: {0} {1}", conn, (NetworkError)errorCode); base.OnClientError(conn, errorCode); ClientError.Invoke(conn, (NetworkError)errorCode); }
public override void OnClientError(NetworkConnection conn, int errorCode) { base.OnClientError(conn, errorCode); ClientError.Invoke(conn, errorCode); }