|
客户端的主要代码:
QTcpSocket TcpSocket_Send;
TcpSocket_Send.connectToHost(QHostAddress(IP),7891);
IsConnect = TcpSocket_Send.waitForConnected(6000);
if(!IsConnect) {
emit Disconnect();
return;
}
服务器端的主要代码:
ServerSocket = new QTcpServer;
ServerSocket->listen(QHostAddress::Any,7891);
connect(ServerSocket,SIGNAL(newConnection()),this,SLOT(NewConnectionHandle()));
void Widget_Receive::NewConnectionHandle()
{
ReceiveSocket = ServerSocket->nextPendingConnection();
connect(ReceiveSocket,SIGNAL(readyRead()),this,SLOT(ReadTcpData()));
CountSpeedTimer->start(1000);
}
void Widget_Receive::ReadTcpData()
{
QByteArray ByteArray = ReceiveSocket->readAll();
TotalRcvByte += ByteArray.size();
} |
|