Qt實現客戶端與伺服器消息發送與文件傳輸

Qt實現客戶端與伺服器消息發送與文件傳輸需要使用到

QTcpSocket:提供套接字
QTcpServer:提供基於TCP的服務端,官方文檔的解釋如下:

This class makes it possible to accept incoming TCP connections. You can specify the port or have QTcpServer pick one automatically. You can listen on a specific address or on all the machine』s addresses.
①指定埠:即開通哪一個埠用於建立TCP連接;
②監聽:監聽①中指定的埠是否有連接的請求。

 

QT提供了QTcpSocket類,可以直接實例化一個客戶端,可在help中索引如下:

The QTcpSocket class provides a TCP socket. More...
Header      #include <QTcpSocket> 
qmake       QT += network
Inherits:   QAbstractSocket
Inherited By:   QSslSocket

所以在使用QTcpSocket、QTcpServer需要在項目的.pro中添加

QT += network

 

Tags: