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