예제 #1
0
파일: Tunnel.cs 프로젝트: nterry/PipeWrench
        public Tunnel(IMessageHandler messageHandler, string friendlyName = "Cactus Fantastico", int port = 14804)
        {
            MessageHandler = messageHandler;

            FriendlyName  = friendlyName;
            _socket       = SockLib.UdpConnect(port);
            _messageQueue = new ConcurrentQueue <Message>();
            _hbMutex      = new SimpleMutex();
            _id           = _tunnelCounter++;
        }
예제 #2
0
        private static Socket CreateSocket()
        {
            const int minPort     = 1025;
            const int maxPort     = 65535;
            var       currentPort = minPort;

            do
            {
                try
                {
                    Logger.DebugFormat("Attempting to bind to local port {0}", currentPort);
                    return(SockLib.UdpConnect(currentPort));
                }
                catch (Exception)
                {
                    Logger.DebugFormat("Failed to bind to port {0}", currentPort);
                    currentPort++;
                }
            } while (currentPort <= maxPort);
            const string message = "Failed to bind to any local ports. Check your firewall.";

            Logger.Error(message);
            throw new IOException(message);
        }