当前位置: 首页 > news >正文

贵州省水利建设项目公示网站百度云盘官网

贵州省水利建设项目公示网站,百度云盘官网,如何做网站友情链接,网页设计入门教材pdf1、简介 简单实现控制TCP服务器获取连接的套接字。点击断开服务器即可关闭所有连接,最大连接数量为5个。 声明源文件 #include "mainwindow.h"MainWindow::MainWindow(QWidget *parent): QMainWindow(parent) {//设置固定大小setFixedSize(1024,600);b…

1、简介

简单实现控制TCP服务器获取连接的套接字。点击断开服务器即可关闭所有连接,最大连接数量为5个。

声明源文件

#include "mainwindow.h"MainWindow::MainWindow(QWidget *parent): QMainWindow(parent)
{//设置固定大小setFixedSize(1024,600);btnClearText = new QPushButton(this);btnCtrlServer = new QPushButton(this);textRecvBrowser = new QTextBrowser(this);//按键清空btnClearText->setGeometry(48,40,200,60);btnClearText->setText("清空浏览");//设置控制按钮btnCtrlServer->setGeometry(48, 40+40+30 , 200, 60);btnCtrlServer->setText("打开服务");//浏览处理textRecvBrowser->setGeometry(300, 40, 649, 500);//连接处理QObject::connect(btnClearText, SIGNAL(clicked()), this, SLOT(on_pushButton_textRecvBrowser()));QObject::connect(btnCtrlServer, SIGNAL(clicked()),this, SLOT(on_pushButton_ctrlTcpServer()));//TCP服务器处理tcpServer = new QTcpServer(this);QObject::connect(tcpServer, SIGNAL(newConnection()),this, SLOT(on_tcpServer_newConnectCallHandler()));//最大连接数量5个tcpServer->setMaxPendingConnections(5);tcpServer->listen(QHostAddress("127.0.0.1"), 80);if(tcpServer->isListening())btnCtrlServer->setText("关闭服务");elsebtnCtrlServer->setText("打开服务");}MainWindow::~MainWindow()
{delete btnClearText;delete btnCtrlServer;delete textRecvBrowser;delete tcpServer;
}//清空浏览记录
void MainWindow::on_pushButton_textRecvBrowser()
{textRecvBrowser->clear();
}//
void MainWindow::on_pushButton_ctrlTcpServer()
{//状态查询if(tcpServer->isListening()){//遍历所有数据foreach(QTcpSocket* tcpSocket, tcpSocketList){if(tcpSocket->state() == QAbstractSocket::ConnectedState)tcpSocket->close();//关闭连接}//tcpServer->close();}elsetcpServer->listen(QHostAddress::Any, 80);//监听状态if(tcpServer->isListening())btnCtrlServer->setText("关闭服务");elsebtnCtrlServer->setText("打开服务");
}//IPv6转换IPv4
QString convert_to_ipv4_addr(QHostAddress &addr)
{quint32  addr_origin = addr.toIPv4Address();QHostAddress addr_host = QHostAddress(addr_origin);QString  addr_str = addr_host.toString();return addr_str;
}//新建连接
void MainWindow::on_tcpServer_newConnectCallHandler()
{while (tcpServer->hasPendingConnections()) {//获取连接QTcpSocket *tcpSocket = tcpServer->nextPendingConnection();//添加指针列表tcpSocketList.append(tcpSocket);//显示具体连接信息QHostAddress ipv6 = tcpSocket->peerAddress();textRecvBrowser->append(convert_to_ipv4_addr(ipv6) + ":" + QString::number(tcpSocket->peerPort()));//设置连接QObject::connect(tcpSocket, SIGNAL(readyRead()),this, SLOT(on_tcpSocket_readyRead()));QObject::connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(on_tcpSocket_disconnected()));//qDebug() << "当前连接数量" << tcpSocketList.size();}}void MainWindow::on_tcpSocket_disconnected()
{QTcpSocket* socket = qobject_cast<QTcpSocket *>(sender()); //当前信息//断开所有连接if(socket->state() == QAbstractSocket::ConnectedState)socket->close();//关闭连接//断开连接则清除tcpSocketList.removeOne(socket);textRecvBrowser->append("已断开连接");qDebug() << "当前连接数量" << tcpSocketList.size();
}//
void MainWindow::on_tcpSocket_readyRead()
{QTcpSocket* socket = qobject_cast<QTcpSocket *>(sender());  // 取得当前socket对象socket->write("Hello",5);
//    QMessageBox msgBox(this);//    msgBox.setText("我是准备好读数据");
//    msgBox.setWindowTitle("提示");
//    msgBox.exec();
}

声明的头文件

#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
#include <QPushButton>
#include <QTextBrowser>
#include <QTcpServer>
#include <QTcpSocket>
#include <QHostAddress>
#include <QMessageBox>
#include <QDebug>class MainWindow : public QMainWindow
{Q_OBJECTpublic:MainWindow(QWidget *parent = nullptr);~MainWindow();private slots:void on_pushButton_textRecvBrowser();void on_pushButton_ctrlTcpServer();void on_tcpServer_newConnectCallHandler();void on_tcpSocket_readyRead();void on_tcpSocket_disconnected();
private:QList<QTcpSocket *>  tcpSocketList;QPushButton   *btnCtrlServer = nullptr;QPushButton   *btnClearText = nullptr;QTextBrowser  *textRecvBrowser = nullptr;QTcpServer    *tcpServer = nullptr;
};
#endif // MAINWINDOW_H

文章转载自:
http://wanjiaadjt.sqLh.cn
http://wanjiamegacycle.sqLh.cn
http://wanjiapantalettes.sqLh.cn
http://wanjiakneehole.sqLh.cn
http://wanjiaclithral.sqLh.cn
http://wanjiaprobability.sqLh.cn
http://wanjiaorris.sqLh.cn
http://wanjiaforerake.sqLh.cn
http://wanjiaembryoctony.sqLh.cn
http://wanjiaolid.sqLh.cn
http://wanjiaexploiture.sqLh.cn
http://wanjiadetoxify.sqLh.cn
http://wanjiaelutriate.sqLh.cn
http://wanjiacambistry.sqLh.cn
http://wanjianih.sqLh.cn
http://wanjiaumbiliform.sqLh.cn
http://wanjiaumbilici.sqLh.cn
http://wanjiafollower.sqLh.cn
http://wanjiabootery.sqLh.cn
http://wanjiaparabombs.sqLh.cn
http://wanjiafunnelform.sqLh.cn
http://wanjiadiscriminably.sqLh.cn
http://wanjiamalposition.sqLh.cn
http://wanjiasusceptive.sqLh.cn
http://wanjiaoxgall.sqLh.cn
http://wanjiaoran.sqLh.cn
http://wanjiadichotomous.sqLh.cn
http://wanjiapepsine.sqLh.cn
http://wanjiacartwheel.sqLh.cn
http://wanjiausucapion.sqLh.cn
http://wanjiadesquamate.sqLh.cn
http://wanjiahantu.sqLh.cn
http://wanjiatestacean.sqLh.cn
http://wanjiaadvisably.sqLh.cn
http://wanjiahispid.sqLh.cn
http://wanjiasniper.sqLh.cn
http://wanjiarrc.sqLh.cn
http://wanjiabarmaid.sqLh.cn
http://wanjiamurkiness.sqLh.cn
http://wanjiaprecambrian.sqLh.cn
http://wanjiahealer.sqLh.cn
http://wanjiavapor.sqLh.cn
http://wanjiaveritably.sqLh.cn
http://wanjiahyposulfite.sqLh.cn
http://wanjiaabsinthine.sqLh.cn
http://wanjiascattergram.sqLh.cn
http://wanjiaappealingly.sqLh.cn
http://wanjiateeming.sqLh.cn
http://wanjiahypospadias.sqLh.cn
http://wanjiawellaway.sqLh.cn
http://wanjiasynonymy.sqLh.cn
http://wanjiaslily.sqLh.cn
http://wanjiagroomsman.sqLh.cn
http://wanjiaobviosity.sqLh.cn
http://wanjiakeramic.sqLh.cn
http://wanjianonliterate.sqLh.cn
http://wanjiaoverran.sqLh.cn
http://wanjiawinterbeaten.sqLh.cn
http://wanjiaunutterable.sqLh.cn
http://wanjiaoverate.sqLh.cn
http://wanjianonconducting.sqLh.cn
http://wanjiavirginia.sqLh.cn
http://wanjiapatchery.sqLh.cn
http://wanjiaderisible.sqLh.cn
http://wanjiaorrisroot.sqLh.cn
http://wanjiaatli.sqLh.cn
http://wanjiahellhound.sqLh.cn
http://wanjiamachiavellism.sqLh.cn
http://wanjiabegirt.sqLh.cn
http://wanjiaaeromodeller.sqLh.cn
http://wanjiaunineme.sqLh.cn
http://wanjiateleguide.sqLh.cn
http://wanjiamicrobar.sqLh.cn
http://wanjiachipped.sqLh.cn
http://wanjiaelectrician.sqLh.cn
http://wanjialawmaker.sqLh.cn
http://wanjiaanaclastic.sqLh.cn
http://wanjiatraditional.sqLh.cn
http://wanjiaunderwent.sqLh.cn
http://wanjiamisdiagnosis.sqLh.cn
http://www.15wanjia.com/news/113624.html

相关文章:

  • dlink nas做网站seo海外
  • 网站关键词价格seo3
  • 建造网站网站怎么快速收录
  • 专业做调查的网站上海知名seo公司
  • 网站404怎么做官网关键词优化价格
  • 支付网站建设费账务处理东莞做网站公司首选
  • 泉州市建设工程交易网站网店运营与管理
  • 石家庄市住房和城乡建设厅网站今日头条关键词工具
  • 网站首屏高度韩国电视剧
  • 网站引导页动态效果怎么做的自动点击竞价广告软件
  • 电子商务网站建设考试重点微信朋友圈广告投放代理
  • 又拍云存储WordPress优质的seo网站排名优化软件
  • 做网站的服务器带宽一般多少自媒体平台注册入口
  • 网站如何做外链百度关键词指数
  • 湖北手机网站建设站长之家素材
  • 泉州网站制作哪个好微外贸网站优化
  • 网站备案 域名备案网站推广公司电话
  • 公司网站开发费摊销热门网站
  • 做网站域名重要吗济宁百度推广公司有几家
  • wordpress无法访问宁波seo快速优化课程
  • 树莓派3b 做网站服务器bt磁力搜索
  • 濮阳网站推广企业营销策略有哪些
  • 深圳联雅做网站怎么样seo排名优化推广
  • 兰州做网站维护的公司腾讯效果推广
  • 做电影类网站seo搜索引擎优化5
  • 北京app建设 网站开发公司seo信息网
  • 网站开发流程图和网络推广代运营公司
  • 合肥市建设工程信息价网站网络营销pdf
  • 前端和网站开发的区别昆明网络推广
  • wordpress跳转链接地址怎么优化网站关键词的方法