使用 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。
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).
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. Please, help.
I'm using Indy that ships with Delphi2010.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Indy 有自己的代理组件,可以满足您的要求。将
TIdMappedPortTCP
和TIdHTTPProxyServer
组件视为起始位置。TIdMappedPortTCP
是一个通用代理,仅来回传递原始数据。您可以使用其 OnConnect 事件动态配置该连接的目标主机/端口(例如通过从客户端读取它),或者您可以设置其 MappedHost 和 <所有连接的 code>MappedPort 静态属性。如果需要,您可以使用其OnExecute
和OnOutboundData
事件在数据通过代理时修改数据。TIdHTTPProxyServer
是仅用于基于 HTTP 的代理的专用代理,其中客户端使用 HTTPGET
、POST
、HEAD
和 CONNECT 动词,指定目标主机/端口的绝对 URL,然后根据需要来回传递 HTTP 标头和数据(CONNECT 通常用于代理通过防火墙的 SSL/TLS 连接)。Indy has its own proxy components that do what you are asking for. Look at the
TIdMappedPortTCP
andTIdHTTPProxyServer
components as starting places.TIdMappedPortTCP
is a general-purpose proxy that just passes raw data back and forth. You can use itsOnConnect
event to dynamically configure the target Host/Port for that connection (such as by reading it from the client), or you can set itsMappedHost
andMappedPort
properties statically for all connections. You can use itsOnExecute
andOnOutboundData
events to modify data as it passes through the proxy, if needed.TIdHTTPProxyServer
is a specialized proxy only for HTTP-based proxying, where the client uses the HTTPGET
,POST
,HEAD
, andCONNECT
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).