代理服务器使用Indy [英] Proxy server using Indy

查看:467
本文介绍了代理服务器使用Indy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Indy的新人,我想用它构建一个简单的代理服务器。这是一个相当大的图书馆,我只是不知道从哪里开始。当客户端连接到服务器时,OnExucute启动并接收客户端连接作为参数(AContext.Connection)。



我想执行以下操作:

  [客户端连接]:= AContext.Connection 
从[客户端连接]读取主机/端口
[远程连接]:=连接到主机/端口
,而两个连接都存在:
如果[客户端连接]中有可用数据:
从[客户端连接]读取数据
将数据写入[远程连接]
如果[远程连接]中提供数据:
从[远程连接]读取数据
将数据写入[客户端连接]

问题是我应该使用哪些功能? Connection对象中有$ code> IOHandler 属性。请帮助。



我使用的是Delphi2010附带的Indy。

解决方案

Indy有自己的代理组件来做你所要求的。看看 TIdMappedPortTCP TIdHTTPProxyServer 组件作为起始位置。



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

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


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.

解决方案

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

这篇关于代理服务器使用Indy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆