代理服务器使用Indy

时间:2010-11-09 16:50:11

标签: delphi networking proxy delphi-2010 indy

我是Indy的新手,我想用它构建一个简单的代理服务器。这是一个非常大的图书馆,我只是不知道从哪里开始。当客户端连接到服务器时,OnExucute将启动并接收客户端连接作为参数(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个属性,其中有大量属性。请帮忙。

我正在使用随Delphi2010一起提供的Indy。

1 个答案:

答案 0 :(得分:20)

Indy拥有自己的代理组件,可以满足您的要求。查看TIdMappedPortTCPTIdHTTPProxyServer组件作为起始位置。

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

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