Example #1
0
        private void ProcessQuery(string query)
        {
            IPAddress address = DnsCache.GetIPAddress(this.host);

            if (address == null)
            {
                this.SendDnsLookupFailedPage(this.host);
                return;
            }
            IPEndPoint remoteEndPoint = new IPEndPoint(address, this.port);

            RemoteSocket = new Socket(remoteEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            if (this.headerFields.ContainsKey("Proxy-Connection") &&
                string.Equals(this.headerFields["Proxy-Connection"], "keep-alive", StringComparison.OrdinalIgnoreCase))
            {
                RemoteSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
            }
            try
            {
                RemoteSocket.BeginConnect(remoteEndPoint, this.OnConnected, RemoteSocket);
            }
            catch (Exception ex)
            {
                Dispose();
                Helper.PublishException(ex);
            }
        }
Example #2
0
        public Listener(ListenerType type, string host, int port)
        {
            IPAddress address;

            if (!IPAddress.TryParse(host, out address))
            {
                address = DnsCache.GetIPAddress(host);
            }
            if (address == null)
            {
                throw new ArgumentException("host " + host + " not found.", "host");
            }
            if (port < 1 || port > 65535)
            {
                throw new ArgumentOutOfRangeException("port[" + port + "] out of range.", "port");
            }

            this._listenerType = type;
            this._address      = address;
            this._host         = host;
            this._port         = port;
            this._clients      = new SynchronizedCollection <IClient>();
        }