简体   繁体   中英

Where can I find a fully working example of a TCP Client and Server for Indy in C++Builder?

I want to create an application that works as a "man in the middle" to analyze a protocol (ISO 8583) sent over TCP/IP.

  1. A client connects to the application and sends some binary data (average length 500 bytes).
  2. The application receives the message and then sends it to the real server.
  3. The server responds to the request to the application.
  4. The application sends the response to the original client.

Some context: The main idea is to get the raw binary data and convert it to a string for parsing and decoding the protocol.

There are two parts to the project:

  1. The gateway part (man in the middle).
  2. Parsing and decoding of the data.

I am expending too much time on the first part. So, if there is a mock-up that I can use to get me started, it will be nice. It doesn't have to be with Indy, but I prefer C++Builder.

This is my first time with Indy, and although I have experience working with TCP/IP, I have always used it as something that is already there, never at the low-level implementation.

I am testing with Hercules , and so far I can see the connections.

  1. When I connect to a server in Hercules, I can see that my application is connecting. But, when my application disconnects, I don't see a message that says so, which means (I think) that my app is not disconnecting correctly (but I can reconnect as many times as I want).

  2. I am sending data to my application using Hercules (a "Hello" string). It is working apparently, but I am having a hard time getting the actual data.

The documentation sometimes gets me into dead links, there are no samples or they are available on Delphi.

I am working with the following:

Windows 11 Home
Embarcadero® C++Builder 10.4 Version 27.0.40680.4203
Delphi and C++ Builder 10.4 Update 2
Indy 10.6.2.0

Have a look at Indy's TIdMappedPortTCP component. It is a TCP server that acts as a MITM proxy between clients and a specified server, giving you events when either party sends raw data.

Use the Bindings collection, or DefaultPort property, to specify the local IP/Port(s) that you want the server to listen for clients on.

Use the MappedHost and MappedPort properties to specify the remote server that you want TIdMappedPortTCP to connect to.

The OnBeforeConnect event is fired when a client has connected to TIdMappePortTCP .

The OnConnect event is fired just before TIdMappedPortTCP attempts to connect to the remote server.

The OnOutboundClientConnect event is fired when TIdMappedPortTCP has connected to the remote server.

The OnExecute event is fired when a client send bytes to TIdMappedPortTCP , and before the bytes are sent to the remote server. The event can alter the bytes, if desired.

The OnOutboundData event is fired when the remote server send bytes to TIdMappedPortTCP , and before the bytes are sent to the client. The event can alter the bytes, if desired.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM