使用 Indy 的代理服务器

发布于 2024-10-01 13:25:08 字数 654 浏览 0 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生生漫 2024-10-08 13:25:08

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

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

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

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

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 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文