Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
828 views
in Technique[技术] by (71.8m points)

delphi - Proxy server using 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...