[英]Proxy server using Indy
I'm new to Indy and I want to build a simple proxy-server with it. 我是Indy的新手,我想用它构建一个简单的代理服务器。 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).
当客户端连接到服务器时,OnExucute将启动并接收客户端连接作为参数(AContext.Connection)。
I want to do following: 我要执行以下操作:
[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]
The question is what functions should I use for that? 问题是我应该使用什么功能? There is
IOHandler
property in Connection object with tons of them. Connection对象中有大量的
IOHandler
属性。 Please, help. 请帮忙。
I'm using Indy that ships with Delphi2010. 我正在使用Delphi2010随附的Indy。
Indy has its own proxy components that do what you are asking for. Indy有自己的代理组件,可以满足您的要求。 Look at the
TIdMappedPortTCP
and TIdHTTPProxyServer
components as starting places. 将
TIdMappedPortTCP
和TIdHTTPProxyServer
组件视为起点。
TIdMappedPortTCP
is a general-purpose proxy that just passes raw data back and forth. TIdMappedPortTCP
是一个通用代理,仅用于来回传递原始数据。 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. 您可以使用它
OnConnect
事件动态配置目标主机/端口为连接(如通过读取来自客户机的话),或者你可以设置其MappedHost
和MappedPort
所有连接静态属性。 You can use its OnExecute
and OnOutboundData
events to modify data as it passes through the proxy, if needed. 如果需要,您可以使用其
OnExecute
和OnOutboundData
事件来修改数据通过代理时的数据。
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). TIdHTTPProxyServer
是仅用于基于HTTP的代理的专用代理,其中客户端使用HTTP GET
, POST
, HEAD
和CONNECT
动词,将绝对URL指定给目标主机/端口,然后根据需要来回传递HTTP标头和数据( CONNECT
通常用于通过防火墙代理SSL / TLS连接)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.