问题描述
我正在尝试编写一个服务器和一组与该服务器通信的客户端.服务器将维护不同客户端的状态,并允许它们在状态更改时向中央服务器发出警报.专业客户将允许控制其他连接的客户.
I am trying to write a server and a set of clients that talk to the server. The server will maintain the status of different clients and allow them to alert the central server when there is a status change. A specialist client will allow the control of the other connected clients.
我将服务器作为TIdCmdTCPServer,并且客户端(目前)使用TIdTCPClient连接.
I have the server as a TIdCmdTCPServer and the clients (at the moment) connect using TIdTCPClient.
如果客户端正在发送和接收命令,它们是否应该使用TIdCmdTCPClient?我已经读过CmdTCPServer和CmdTCPClient并没有真正一起使用-是不是必须一起使用?
If the clients are sending and recieving commands, should they use TIdCmdTCPClient? I have read that the CmdTCPServer and CmdTCPClient are not really used together - is it that they don't have to be used together?
对这个问题的普遍模糊性表示歉意,但是我真的才刚刚开始研究这个问题,在我陷入困境之前还需要采取一些预防措施.
So apologies for the general vagueness of the question, but I have only really just started looking at this and need a sort of heads out before I get bogged down in details.
感谢您的帮助
标记H
推荐答案
从技术上讲,可以将TIdCmdTCPClient和TIdCmdTCPServer一起使用,但通常不建议这样做.这些组件设计用于异步处理入站命令.让客户端等待服务器命令没有意义,但是让服务器同时等待客户端命令没有意义.这是使您的连接陷入僵局的好方法,因为他们俩都在等待对方的数据,而且两个都没有在没有输入的情况下发送任何内容.
It is technically possible to use use TIdCmdTCPClient and TIdCmdTCPServer together, but in general it is not advisable. Those components are designed for processing inbound commands asynchronously. It does not make sense to have a client waiting for server commands, but to have a server waiting for client commands at the same time. That is a good way to deadlock your connection, as they are both waiting for data from each other, and neither is actually sending anything without input first.
这篇关于是否应该一起使用TIdCmdTCPServer和TIdCmdTCPClient?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!