Example #1
0
 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);
     }
 }
Example #2
0
 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);
 }
Example #3
0
 public override void OnClientError(NetworkConnection conn, int errorCode)
 {
     base.OnClientError(conn, errorCode);
     ClientError.Invoke(conn, errorCode);
 }