Exemplo n.º 1
0
 public T Read <T>() where T : Message
 {
     try
     {
         if (!Client.Connected)
         {
             var connection = new TcpConnection(Client);
             var args       = new TcpConnectionArgs
             {
                 Connection = connection
             };
             OnDisconnect?.Invoke(this, args);
             return(default(T));
         }
         var stream = Client.GetStream();
         if (stream.DataAvailable)
         {
             return(stream.Read <T>());
         }
     }
     catch (Exception)
     {
         var connection = new TcpConnection(Client);
         var args       = new TcpConnectionArgs
         {
             Connection = connection
         };
         OnDisconnect?.Invoke(this, args);
     }
     return(default(T));
 }
Exemplo n.º 2
0
 public void Send(Message message)
 {
     try
     {
         if (!this.Client.Connected)
         {
             var connection = new TcpConnection(Client);
             var args       = new TcpConnectionArgs
             {
                 Connection = connection
             };
             OnDisconnect?.Invoke(this, args);
             return;
         }
         this.Client.Send(message);
     }
     catch (Exception)
     {
         var connection = new TcpConnection(Client);
         var args       = new TcpConnectionArgs
         {
             Connection = connection
         };
         OnDisconnect?.Invoke(this, args);
         return;
     }
 }