Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我们有一个在 TCP 服务器模式下运行的设备。所以我必须连接到它才能开始发送和接收。
我用 IdTcpClient 连接到它。但我不知道如何使用 IdTcpClient 获取它的数据(IdTcpClient 没有 OnExecute 事件)。
我得到它的端口(端口是动态的)来发送数据(我有一个防火墙)。但是我不能用 IdTCPServer 监听它,我得到这个错误:“无法绑定套接字。地址和端口已经在使用中”。
如何获取传入数据(使用 IdTcpClient)并向其发送命令?我在某个地方有错误吗?
连接到设备后,您可以在需要时对其进行读取和写入。如果您不想挂起您的主 UI 线程,您应该在工作线程中执行您的套接字 I/O。这与 Indy 的阻塞 I/O 模型配合得很好。您可以使用TThread它,并覆盖它的Execute()方法。或者使用 Indy 的TIdThreadComponent组件。
TThread
Execute()
TIdThreadComponent
您首先需要阅读“设备”的手册。并找出您的设备期望您执行哪些操作来读取数据。您不能两次打开同一个端口。