예제 #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));
 }
예제 #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;
     }
 }