简体   繁体   English

我在哪里可以找到 C++Builder 中 Indy 的 TCP 客户端和服务器的完整工作示例?

[英]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.我想创建一个应用程序作为“中间人”来分析通过 TCP/IP 发送的协议 (ISO 8583)。

  1. A client connects to the application and sends some binary data (average length 500 bytes).客户端连接到应用程序并发送一些二进制数据(平均长度 500 字节)。
  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.它不必与 Indy 一起使用,但我更喜欢 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.这是我第一次使用 Indy,虽然我有使用 TCP/IP 的经验,但我总是将它当作已经存在的东西来使用,而不是在低级实现中使用。

I am testing with Hercules , and so far I can see the connections.我正在测试Hercules ,到目前为止我可以看到连接。

  1. When I connect to a server in Hercules, I can see that my application is connecting.当我连接到 Hercules 中的服务器时,我可以看到我的应用程序正在连接。 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).我正在使用 Hercules(“Hello”字符串)向我的应用程序发送数据。 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.文档有时会让我进入死链接,没有示例或者它们可以在 Delphi 上找到。

I am working with the following:我正在处理以下内容:

Windows 11 Home Windows 11 家
Embarcadero® C++Builder 10.4 Version 27.0.40680.4203 Embarcadero® C++Builder 10.4 版本 27.0.40680.4203
Delphi and C++ Builder 10.4 Update 2 Delphi 和 C++ Builder 10.4 更新 2
Indy 10.6.2.0印地 10.6.2.0

Have a look at Indy's TIdMappedPortTCP component.看看 Indy 的TIdMappedPortTCP组件。 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.它是一个 TCP 服务器,充当客户端和指定服务器之间的 MITM 代理,在任何一方发送原始数据时为您提供事件。

Use the Bindings collection, or DefaultPort property, to specify the local IP/Port(s) that you want the server to listen for clients on.使用Bindings集合或DefaultPort属性指定您希望服务器侦听客户端的本地 IP/端口。

Use the MappedHost and MappedPort properties to specify the remote server that you want TIdMappedPortTCP to connect to.使用MappedHostMappedPort属性指定您希望TIdMappedPortTCP连接到的远程服务器。

The OnBeforeConnect event is fired when a client has connected to TIdMappePortTCP .当客户端连接到TIdMappePortTCP时,将触发OnBeforeConnect事件。

The OnConnect event is fired just before TIdMappedPortTCP attempts to connect to the remote server. OnConnect事件在TIdMappedPortTCP尝试连接到远程服务器之前触发。

The OnOutboundClientConnect event is fired when TIdMappedPortTCP has connected to the remote server.TIdMappedPortTCP连接到远程服务器时,将触发OnOutboundClientConnect事件。

The OnExecute event is fired when a client send bytes to TIdMappedPortTCP , and before the bytes are sent to the remote server.当客户端向TIdMappedPortTCP发送字节时,以及在将字节发送到远程服务器之前,会触发OnExecute事件。 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. OnOutboundData事件在远程服务器发送字节到TIdMappedPortTCP时被触发,在字节被发送到客户端之前。 The event can alter the bytes, if desired.如果需要,事件可以改变字节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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