我是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。
答案 0 :(得分:20)
Indy拥有自己的代理组件,可以满足您的要求。查看TIdMappedPortTCP
和TIdHTTPProxyServer
组件作为起始位置。
TIdMappedPortTCP
是一个通用代理,只是来回传递原始数据。您可以使用其OnConnect
事件为该连接动态配置目标主机/端口(例如通过从客户端读取),也可以静态设置其MappedHost
和MappedPort
属性对于所有连接。如果需要,您可以使用其OnExecute
和OnOutboundData
事件修改通过代理的数据。
TIdHTTPProxyServer
是仅适用于基于HTTP的代理的专用代理,客户端使用HTTP GET
,POST
,HEAD
和CONNECT
动词,指定目标主机/端口的绝对URL,然后根据需要来回传递HTTP头和数据(CONNECT
通常用于通过防火墙代理SSL / TLS连接。)