public static TunnelSocket GetOrCreateTunnelSocket(short port)
        {
            TunnelSocket b;
            short        p = port;

            if (sTunnels.Find(ref p, out b))
            {
                return(b);
            }
            else
            {
                b = new TunnelSocket(port);
                b.Start();
            }
            return(b);
        }
 static TunnelRuntime()
 {
     sTunnels = new TreeDictionary <short, TunnelSocket>();
     //when the application is about to shutdown we should free the open
     //connections
     AppDomain.CurrentDomain.DomainUnload += (object sender, EventArgs e) =>
     {
         foreach (short port in sTunnels.Keys)
         {
             TunnelSocket sock;
             short        refPort = port;
             sTunnels.Find(ref refPort, out sock);
             sock.Close();
         }
     };
 }