예제 #1
0
        public static async Task <SocksProxyReply> ReadReplyAsync(Stream s)
        {
            SocksProxyReply reply = new SocksProxyReply();

            byte[] buffer = new byte[3];

            await s.ReadBytesAsync(buffer, 0, 3);

            reply._version = buffer[0];
            reply._reply   = (SocksProxyReplyCode)buffer[1];
            reply._bindEP  = await SocksProxyServer.ReadEndPointAsync(s);

            return(reply);
        }
예제 #2
0
        private static async Task <EndPoint> RequestAsync(Stream s, SocksProxyRequest request)
        {
            await request.WriteToAsync(s);

            await s.FlushAsync();

            SocksProxyReply reply = await SocksProxyReply.ReadReplyAsync(s);

            if (!reply.IsVersionSupported)
            {
                throw new SocksProxyException("Socks version 5 is not supported by the proxy server.");
            }

            if (reply.ReplyCode != SocksProxyReplyCode.Succeeded)
            {
                throw new SocksProxyException("Socks proxy server request failed: " + reply.ReplyCode.ToString(), reply.ReplyCode);
            }

            return(reply.BindEndPoint);
        }
예제 #3
0
        public async Task <Socket> AcceptAsync()
        {
            SocksProxyReply reply = await SocksProxyReply.ReadReplyAsync(new NetworkStream(_socket));

            if (!reply.IsVersionSupported)
            {
                throw new SocksProxyException("Socks version 5 is not supported by the proxy server.");
            }

            if (reply.ReplyCode != SocksProxyReplyCode.Succeeded)
            {
                throw new SocksProxyException("Socks proxy server request failed: " + reply.ReplyCode.ToString(), reply.ReplyCode);
            }

            _remoteEP = reply.BindEndPoint;

            Socket socket = _socket;

            _socket = null; //prevent socket from getting disposed

            return(socket);
        }