簡體   English   中英

如何在 QT 中通過 C++ 中的套接字發送和接收?

[英]How to send and receive over sockets in C++ in 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 中沒有找到方法名來發送數據。 這樣做的方法名稱是什么?

您可以通過閱讀文檔查看所有可用的方法。 此鏈接中有 QTcpSocket 繼承的 QAbstractSocket 類的文檔。

無論如何,您要使用的方法是write()發送數據,您可以檢查是否可以使用bytesAvailable()讀取數據並使用read()readData()讀取數據。 這些 las 方法是從 QIODevice 類繼承和重新實現的,您也可以在文檔中找到。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM