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++; }
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); }