示例#1
0
 public void Connect(string host, int port)
 {
     ReceivedLength         = 0;
     Encryption.Initialized = false;
     Socket = SocketFactory.CreateSocket();
     Socket.BeginConnect(host, port, ConnectCallback, null);
 }
示例#2
0
 public void Connect(string host, int port)
 {
     _receivedLength         = 0;
     _encryption.Initialized = false;
     _socket = _socketFactory.CreateSocket();
     Log.Info($"Connecting to {host}:{port}");
     _socket.BeginConnect(host, port, ConnectCallback, null);
 }
示例#3
0
 public void Connect()
 {
     try
     {
         clientSocket.BeginConnect(ipendPoint_0, VvVnOpsTju, null);
     }
     catch
     {
         try
         {
             OnCloseCon onCloseCon = onCloseCon_0;
             if (onCloseCon != null)
             {
                 onCloseCon();
             }
         }
         catch
         {
         }
         Dispose();
     }
 }
        private void OpenHostConnection(Connection conn)
        {
            if (conn.host_found)
            {
                throw new Exception("Already have host");       //should never happen
            }
            #region Get Host from headers
            {
                MemoryStream str_mem = conn.buf_str;
                str_mem.Position = conn.host_last_read_pos;

                string raw_host_line;
                while ((raw_host_line = ReadLine(str_mem, ASCIIEncoding.ASCII)) != null)
                {
                    conn.host_last_read_pos = str_mem.Position;

                    if (raw_host_line.Length == 0)
                    {
                        throw new Exception("Failed to find Host in request headers");
                    }

                    int idx_split;
                    if ((idx_split = raw_host_line.IndexOf(':')) > 0 && idx_split < raw_host_line.Length)
                    {
                        string key = raw_host_line.Substring(0, idx_split);
                        string val = raw_host_line.Substring(idx_split + 1).Trim();

                        if (key.Equals("host", StringComparison.InvariantCultureIgnoreCase))
                        {
                            string[] host_parts = val.Split(':');

                            if (host_parts.Length == 1)
                            {
                                conn.host_loc = new IPLocation(host_parts[0], 80);
                            }
                            else if (host_parts.Length == 2)
                            {
                                conn.host_loc = new IPLocation(host_parts[0], Int32.Parse(host_parts[1]));
                            }
                            else
                            {
                                throw new Exception(String.Format("Failed to parse HOST from '{0}'", raw_host_line));
                            }

                            conn.host_found = true;
                        }
                    }
                }

                str_mem.Seek(0, SeekOrigin.End);
            }
            #endregion

            #region Open Host Connection
            {
                if (conn.host_found)
                {
                    try
                    {
                        ProxySocket skt = new ProxySocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                        skt.ProxyEndPoint = EndPoint_Destination_Socks;
                        skt.ProxyType     = ProxyTypes.Socks5;
                        conn.host_socket  = skt;

                        if (conn.host_loc.port == 443)
                        {
                            Console.WriteLine("HTTPS is not suported.");
                        }

                        skt.BeginConnect(conn.host_loc.host, conn.host_loc.port, Host_Connected, conn);
                    }
                    catch (ObjectDisposedException e)
                    {
                        if (!Handle_Disposed(e, conn))
                        {
                            throw;
                        }
                    }
                }
            }
            #endregion
        }