コード例 #1
0
 public void CloseConn() // Close connection.
 {
     try
     {
         notEnd = false;
         StreamReader.Close();
         StreamWriter.Close();
         networkStream.Close();
         tcpClient.Close();
         Console.WriteLine("[{0}] End of connection!", DateTime.Now);
         log.Info("End of connection!");
     }
     catch (Exception e)
     {
         log.Error("Error mientras se cerraba la conexion", e);
         //  Console.WriteLine(e.StackTrace);
         Console.WriteLine(e.Message);
     }
     finally
     {
         if (onConnectionDropDelegate != null)
         {
             ConnectionDroppedDelegate tmp = onConnectionDropDelegate;
             log.InfoFormat("Conexion {0} anula para el delegado y lo invoca", Name);
             onConnectionDropDelegate = null;
             tmp(Name);
         }
     }
     notEnd = false;
 }
コード例 #2
0
 public Connection(string name, TcpClient c, IReceiveEvent ire, ConnectionDroppedDelegate dropConDelegate)
 {
     onConnectionDropDelegate = dropConDelegate;
     IsServer     = false;
     Name         = name;
     tcpClient    = c;
     EventHandler = ire;
     semWrite     = new Semaphore(0, 1);
     semRead      = new Semaphore(0, 1);
     (threadRead = new Thread(new ThreadStart(SetupConn))).Start();
 }