简体   繁体   中英

How to send and receive over sockets in C++ in QT?

I want to do this

For the server:

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();

For the client

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

I did not find a method name in QTcpServer to retrieve data and in QTcpClient to send data. What are the methods names to do that ?

You can see all the methods available reading the documentation. In this link there is the documentation for QAbstractSocket Class inherited by QTcpSocket.

Anyway the methods you want to use are write() to send data and you can check if data is available to read with bytesAvailable() and read data with read() or readData() . These las methods are inherited and reimplemented from QIODevice Class, that you can also find in the documentation .

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