如何在QT中用C ++发送和接收套接字?

时间:2017-01-13 02:00:35

标签: c++ qt

我想这样做

对于服务器:

QTcpServer qtp;
qtp.listen(QHostAddress::Any, 1440);
qtp.readFromClient(); //What is the name of the method to read the byte from a  client ???
qtp.close();

对于客户

QTcpClient client;
client.connect("127.0.0.1", 1440);
client.sendData(myString); // What is the name of the method to do this ???  
client.close();

我没有在QTcpServer中找到方法名来检索数据,而在QTcpClient中找不到方法名来发送数据。有什么方法可以做到这一点?

1 个答案:

答案 0 :(得分:0)

您可以查看阅读文档的所有可用方法。在this link中,有QTcpSocket继承的QAbstractSocket类的文档。

无论如何,您要使用write()方法发送数据,您可以检查数据是否可以通过bytesAvailable()阅读,并使用read()readData()读取数据。这些las方法是从QIODevice类继承并重新实现的,您也可以在documentation中找到。