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