使用 Indy 的代理服务器 [英] Proxy server using Indy

查看:51
本文介绍了使用 Indy 的代理服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Indy 的新手,我想用它构建一个简单的代理服务器.这是一个相当大的图书馆,我只是不知道从哪里开始.当客户端连接到服务器时,OnExucute 启动并接收客户端连接作为参数 (AContext.Connection).

I'm new to Indy and I want to build a simple proxy-server with it. This is a quite big library, and I just don't know where to start. When client connects to server, OnExucute fires up and receives client connection as parameter (AContext.Connection).

我想做以下事情:

[client connection] := AContext.Connection
read host/port from [client connection]
[remote connection] := connect to host/port
while both connections alive:
  if data available in [client connection]:
    read data from [client connection]
    write data to [remote connection]
  if data available in [remote connection]:
    read data from [remote connection]
    write data to [client connection]

问题是我应该为此使用哪些函数?Connection 对象中有 IOHandler 属性,其中有很多.请帮忙.

The question is what functions should I use for that? There is IOHandler property in Connection object with tons of them. Please, help.

我使用的是随 Delphi2010 一起提供的 Indy.

I'm using Indy that ships with Delphi2010.

推荐答案

Indy 有自己的代理组件,可以满足您的要求.将 TIdMappedPortTCPTIdHTTPProxyServer 组件视为起始位置.

Indy has its own proxy components that do what you are asking for. Look at the TIdMappedPortTCP and TIdHTTPProxyServer components as starting places.

TIdMappedPortTCP 是一个通用的代理,它只是来回传递原始数据.您可以使用其 OnConnect 事件为该连接动态配置目标主机/端口(例如通过从客户端读取它),或者您可以设置其 MappedHostMappedPort 属性静态地用于所有连接.如果需要,您可以使用其 OnExecuteOnOutboundData 事件在数据通过代理时修改数据.

TIdMappedPortTCP is a general-purpose proxy that just passes raw data back and forth. You can use its OnConnect event to dynamically configure the target Host/Port for that connection (such as by reading it from the client), or you can set its MappedHost and MappedPort properties statically for all connections. You can use its OnExecute and OnOutboundData events to modify data as it passes through the proxy, if needed.

TIdHTTPProxyServer 是专门用于基于 HTTP 代理的代理,其中客户端使用 HTTP GETPOSTHEADCONNECT 动词,指定目标主机/端口的绝对 URL,然后根据需要来回传递 HTTP 标头和数据(CONNECT 通常用于用于通过防火墙代理 SSL/TLS 连接).

TIdHTTPProxyServer is a specialized proxy only for HTTP-based proxying, where the client uses the HTTP GET, POST, HEAD, and CONNECT verbs, specifying absolute URLs to the target Host/Port, and then passes HTTP headers and data back and forth as needed (CONNECT is commonly used for proxying an SSL/TLS connection through a firewall).

这篇关于使用 Indy 的代理服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆