91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 19KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2021-06-15
  • 語言: 其他
  • 標簽: TCP??多客戶端??

資源簡介

QT TCP一個服務端連接多個客戶端通信,歡迎大家參考!

資源截圖

代碼片段和文件信息

#include?“frmmain.h“
#include?“ui_frmmain.h“
#include?“myhelper.h“

frmMain::frmMain(QWidget?*parent)?:
????QWidget(parent)
????ui(new?Ui::frmMain)
{
????ui->setupUi(this);

????FormHelper::FormInCenter(this);
????FormHelper::FormNotResize(this);????

????this->Init();
}

frmMain::~frmMain()
{
????delete?ui;
}

void?frmMain::Init()
{
????ui->btnSend->setEnabled(false);
????ui->txtReceive->setReadOnly(true);
????tcpClient=new?QTcpSocket(this);
????tcpClient->abort();//取消原有連接
????connect(tcpClientSIGNAL(readyRead())thisSLOT(ReadData()));
????connect(tcpClientSIGNAL(error(QAbstractSocket::SocketError))thisSLOT(ReadError(QAbstractSocket::SocketError)));
}

void?frmMain::ReadData()
{
????QByteArray?buffer=tcpClient->readAll();
????if?(!buffer.isEmpty())
????{
????????if?(ui->ckHexReceive->isChecked())
????????{
????????????ui->txtReceive->append(“接收數據:“+myHelper::ByteArrayToHexStr(buffer));
????????}
????????else
????????{
????????????ui->txtReceive->append(“接收數據:“+buffer);
????????}
????}
}

void?frmMain::ReadError(QAbstractSocket::SocketError)
{
????tcpClient->disconnectFromHost();
????ui->btnConnect->setText(“連接“);
????ui->txtReceive->append(tr(“連接服務器失敗原因:%1“).arg(tcpClient->errorString()));
}

void?frmMain::on_btnConnect_clicked()
{
????if?(ui->btnConnect->text()==“連接“)
????{
????????tcpClient->connectToHost(ui->txtIP->text()ui->txtPort->text().toInt());
????????if?(tcpClient->waitForConnected(1000))
????????{
????????????ui->btnConnect->setText(“斷開“);
????????????ui->txtReceive->append(“連接服務器成功“);
????????????ui->btnSend->setEnabled(true);
????????}
????}
????else
????{
????????tcpClient->disconnectFromHost();
????????tcpClient->waitForDisconnected(1000);
????????if?(tcpClient->state()?==?QAbstractSocket::UnconnectedState?||?tcpClient->waitForDisconnected(1000))
????????{
????????????ui->btnConnect->setText(“連接“);
????????????ui->txtReceive->append(“斷開連接成功“);
????????????ui->btnSend->setEnabled(true);
????????}
????}
}

void?frmMain::on_btnClear_clicked()
{
????ui->txtReceive->clear();
}

void?frmMain::on_btnSend_clicked()
{
????QString?data=ui->txtSend->text();

????if?(data!=““)
????{
????????if?(ui->ckHexSend->isChecked())
????????{
????????????tcpClient->write(myHelper::HexStrToByteArray(data));
????????}
????????else
????????{
????????????tcpClient->write(data.toLatin1());
????????}
????}
}

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-05-13?17:01??Qt?TCP多客戶端通信\
?????目錄???????????0??2016-05-07?11:43??Qt?TCP多客戶端通信\myTcpClient\
?????文件????????2534??2016-05-05?17:09??Qt?TCP多客戶端通信\myTcpClient\frmmain.cpp
?????文件?????????559??2013-09-03?15:44??Qt?TCP多客戶端通信\myTcpClient\frmmain.h
?????文件????????5036??2013-09-04?17:05??Qt?TCP多客戶端通信\myTcpClient\frmmain.ui
?????文件?????????278??2016-05-05?17:06??Qt?TCP多客戶端通信\myTcpClient\main.cpp
?????文件???????15044??2016-05-05?17:04??Qt?TCP多客戶端通信\myTcpClient\myhelper.h
?????文件?????????505??2016-05-05?14:04??Qt?TCP多客戶端通信\myTcpClient\myTcpClient.pro
?????文件???????18266??2016-05-05?17:22??Qt?TCP多客戶端通信\myTcpClient\myTcpClient.pro.user
?????目錄???????????0??2016-05-13?16:36??Qt?TCP多客戶端通信\myTcpServer\
?????文件????????3568??2016-05-13?16:36??Qt?TCP多客戶端通信\myTcpServer\frmmain.cpp
?????文件?????????770??2016-05-10?10:14??Qt?TCP多客戶端通信\myTcpServer\frmmain.h
?????文件????????4535??2016-05-06?13:26??Qt?TCP多客戶端通信\myTcpServer\frmmain.ui
?????文件?????????187??2016-05-13?15:33??Qt?TCP多客戶端通信\myTcpServer\main.cpp
?????文件?????????905??2016-05-10?17:39??Qt?TCP多客戶端通信\myTcpServer\myclientsocket.cpp
?????文件?????????519??2013-09-04?09:49??Qt?TCP多客戶端通信\myTcpServer\myclientsocket.h
?????文件????????2268??2016-05-13?15:32??Qt?TCP多客戶端通信\myTcpServer\mytcpserver.cpp
?????文件?????????921??2016-05-13?15:13??Qt?TCP多客戶端通信\myTcpServer\mytcpserver.h
?????文件?????????590??2016-05-06?14:00??Qt?TCP多客戶端通信\myTcpServer\myTcpServer.pro
?????文件???????18266??2016-05-11?18:17??Qt?TCP多客戶端通信\myTcpServer\myTcpServer.pro.user

評論

共有 條評論