protected override void HandleClient(object clientObj)
        {
            TcpClient socket2Client = clientObj as TcpClient;

            Pipe client2Server = new Pipe(
                socket2Client,
                null
                );
            Pipe server2Client = new Pipe(
                null,
                socket2Client
                );

            client2Server.EncryptFrom = true;
            server2Client.EncryptTo   = true;
            try
            {
                byte[] request = client2Server.Read();
                if (request == null)
                {
                    return;
                }
                // not socket 5 request
                int version = request[0];
                if (version != '\u0005')
                {
                    return;
                }

                string reply = "\u0005\u0000";
                server2Client.Write(reply);

                request = client2Server.Read();
                if (request == null)
                {
                    return;
                }

                CMDType cmdType = (CMDType)request[1];

                if (cmdType == CMDType.Connect)
                {
                    HandleTCPReq(request, server2Client, client2Server);
                }
                else if (cmdType == CMDType.Udp)
                {
                    //HandleUDPReq(request, server2Client);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                client2Server.Close();
                server2Client.Close();
            }
        }
Beispiel #2
0
        protected override bool WorkFlow(Pipe pipeClient2Server, Pipe pipeServer2Client)
        {
            string     request = pipeClient2Server.ReadString();
            IPEndPoint reqIPEP = GetIPEndPoint(request);

            if (SendReqEndPoint(pipeClient2Server.SocketTo, reqIPEP))
            {
                if (reqIPEP.Port == 443)
                {
                    string re443 = "HTTP/1.1 OK\r\n\r\n";
                    return(pipeServer2Client.Write(re443));
                }
                else
                {
                    return(pipeClient2Server.Write(request));
                }
            }
            return(false);
        }
        private void CloseRequest(Pipe server2Client)
        {
            string reply = "\u0005\u0001\u0000\u0001\u0000\u0000\u0000\u0000\u0000\u0000";

            server2Client.Write(reply);
        }
        protected override void HandleClient(object clientObj)
        {
            TcpClient socket2Client = clientObj as TcpClient;

            Pipe pipe0;
            Pipe pipe1 = null;

            pipe0 = new Pipe(
                socket2Client,
                null
                );
            pipe0.EncryptFrom = true;
            try
            {
                byte[] buffer = pipe0.Read();
                if (buffer == null)
                {
                    return;
                }
                string request = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
                string host    = GetHost(request);
                int    port    = GetPort(request);
                if (host == "" || port == 0)
                {
                    return;
                }
                IPHostEntry iphe = Dns.GetHostEntry(host);
                IPAddress   ipa  = null;
                foreach (IPAddress tmp in iphe.AddressList)
                {
                    if (tmp.AddressFamily == AddressFamily.InterNetwork)
                    {
                        ipa = tmp;
                    }
                }
                if (ipa == null)
                {
                    return;
                }
                string ip = ipa.ToString();
                Console.WriteLine("connect to " + host + ":" + port);

                TcpClient client2Server = new TcpClient(ip, port);

                pipe1 = new Pipe(
                    client2Server,
                    socket2Client
                    );
                pipe1.EncryptTo = true;

                pipe0.ClientTo = client2Server;

                if (port == 443)
                {
                    string re443 = "HTTP/1.1 OK\r\n\r\n";
                    buffer = Encoding.UTF8.GetBytes(re443);
                    pipe1.Write(buffer);
                }
                else
                {
                    pipe0.Write(buffer);
                }

                pipe0.Flow();
                pipe1.Flow();
            }
            catch (SocketException se)
            {
                Console.WriteLine(se.Message);
                pipe0.Close();
                if (pipe1 != null)
                {
                    pipe1.Close();
                }
            }
        }
 public bool WriteR(string msg, Encoding code)
 {
     return(pipeL2R.Write(msg, code) > 0);
 }
 public bool WriteL(string msg, Encoding code)
 {
     return(pipeR2L.Write(msg, code) > 0);
 }
Beispiel #7
0
 public bool WriteR(string msg)
 {
     return(pipeL2R.Write(msg));
 }
Beispiel #8
0
 public bool WriteL(string msg)
 {
     return(pipeR2L.Write(msg));
 }