public static GenericSocksHandler GetInstance(TcpClient client) { var buffer = new byte[BufferSize]; var stream = client.GetStream(); var size = stream.Read(buffer, 0, BufferSize); Array.Resize(ref buffer, size); if (size < 3) { throw new ArgumentException(Strings.INVALID_SOCKS_HANDSHAKE); } GenericSocksHandler result = new Socks4Handler(buffer); if (!result.IsHandled) { result = new Socks4AHandler(buffer); if (!result.IsHandled) { result = new Socks5Handler(client, buffer); if (!result.IsHandled) { throw (new ArgumentException(Strings.NO_VALID_SOCKS_HANDLER)); } } } var reply = result.Reply; client.GetStream().Write(reply, 0, reply.Length); return(result); }
/// ----------------------------------------------------------------------------- /// <summary> /// Retourne un gestionnaire adapté à la requête /// </summary> /// <param name="client">le client TCP</param> /// <returns>un gestionnaire adapté</returns> /// ----------------------------------------------------------------------------- public static GenericSocksHandler GetInstance(TcpClient client) { var buffer = new byte[BufferSize]; var stream = client.GetStream(); var size = stream.Read(buffer, 0, BufferSize); Array.Resize(ref buffer, size); if (size < 3) throw (new ArgumentException(Strings.INVALID_SOCKS_HANDSHAKE)); GenericSocksHandler result = new Socks4Handler(buffer); if (!result.IsHandled) { result = new Socks4AHandler(buffer); if (!result.IsHandled) { result = new Socks5Handler(client, buffer); if (!result.IsHandled) throw (new ArgumentException(Strings.NO_VALID_SOCKS_HANDLER)); } } var reply = result.Reply; client.GetStream().Write(reply, 0, reply.Length); return result; }