delphi – 使用Indy的代理服务器

前端之家收集整理的这篇文章主要介绍了delphi – 使用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属性,其中有吨.请帮忙.

我用Indy搭配Delphi2010.

解决方法

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

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

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

原文链接:https://www.f2er.com/delphi/102832.html

猜你在找的Delphi相关文章