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

asp网站变慢宝安logo设计

asp网站变慢,宝安logo设计,wordpress延时加载插件,哪些公司做网站好为大家分享一下最近封装的以太网socket通讯接口 效果演示 如图#xff0c;界面还没优化#xff0c;后续更新 废话不多说直接上教程 添加库 如果为qmake项目中#xff0c;在.pro文件添加 QT network QT core gui QT networkgreaterThan(QT_MAJOR_VERS…为大家分享一下最近封装的以太网socket通讯接口 效果演示 如图界面还没优化后续更新 废话不多说直接上教程 添加库 如果为qmake项目中在.pro文件添加   QT  network QT core gui QT networkgreaterThan(QT_MAJOR_VERSION, 4): QT widgetsCONFIG c17 Socket封装 头文件// SocketManager.h #ifndef SOCKETMANAGER_H #define SOCKETMANAGER_H#include QObject #include QTcpSocket #include QTcpServer #include QUdpSocket #include functionalclass SocketManager : public QObject {Q_OBJECTpublic:enum class Protocol { TCP, UDP };explicit SocketManager(QObject *parent nullptr);~SocketManager();// Set the callback for incoming messagesvoid setMessageCallback(const std::functionvoid(const QByteArray ) callback);// Initialize the socketbool initialize(Protocol protocol, const QString host, quint16 port, bool isServer false);// Send a messageqint64 sendMessage(const QByteArray message);private slots:void onReadyRead();private:Protocol m_protocol;QTcpSocket *m_tcpSocket nullptr;QTcpServer *m_tcpServer nullptr;QUdpSocket *m_udpSocket nullptr;std::functionvoid(const QByteArray ) m_messageCallback;void handleIncomingConnection(); };#endif // SOCKETMANAGER_H源文件// SocketManager.cpp #include SocketManager.hSocketManager::SocketManager(QObject *parent): QObject(parent) { }SocketManager::~SocketManager() {if (m_tcpSocket) delete m_tcpSocket;if (m_tcpServer) delete m_tcpServer;if (m_udpSocket) delete m_udpSocket; }void SocketManager::setMessageCallback(const std::functionvoid(const QByteArray ) callback) {m_messageCallback callback; }bool SocketManager::initialize(Protocol protocol, const QString host, quint16 port, bool isServer) {m_protocol protocol;if (protocol Protocol::TCP) {if (isServer) {m_tcpServer new QTcpServer(this);connect(m_tcpServer, QTcpServer::newConnection, this, SocketManager::handleIncomingConnection);return m_tcpServer-listen(QHostAddress(host), port);} else {m_tcpSocket new QTcpSocket(this);m_tcpSocket-connectToHost(host, port);connect(m_tcpSocket, QTcpSocket::readyRead, this, SocketManager::onReadyRead);return m_tcpSocket-waitForConnected();}} else if (protocol Protocol::UDP) {m_udpSocket new QUdpSocket(this);connect(m_udpSocket, QUdpSocket::readyRead, this, SocketManager::onReadyRead);return m_udpSocket-bind(QHostAddress(host), port);}return false; }qint64 SocketManager::sendMessage(const QByteArray message) {if (m_protocol Protocol::TCP m_tcpSocket) {return m_tcpSocket-write(message);} else if (m_protocol Protocol::UDP m_udpSocket) {return m_udpSocket-writeDatagram(message, QHostAddress::Broadcast, m_udpSocket-localPort());}return -1; }void SocketManager::onReadyRead() {if (m_protocol Protocol::TCP m_tcpSocket) {QByteArray data m_tcpSocket-readAll();if (m_messageCallback) {m_messageCallback(data);}} else if (m_protocol Protocol::UDP m_udpSocket) {while (m_udpSocket-hasPendingDatagrams()) {QByteArray data;data.resize(m_udpSocket-pendingDatagramSize());m_udpSocket-readDatagram(data.data(), data.size());if (m_messageCallback) {m_messageCallback(data);}}} }void SocketManager::handleIncomingConnection() {if (m_tcpServer) {m_tcpSocket m_tcpServer-nextPendingConnection();connect(m_tcpSocket, QTcpSocket::readyRead, this, SocketManager::onReadyRead);} }使用方式 首先引入#include SocketManager.h 初始化 通过enum class Protocol { TCP, UDP };来选择TCP/UDP 通过第三个参数来决定如果是TCP的话是Service服务端还是Client客户端 socketManager new SocketManager(this);if (socketManager-initialize(SocketManager::Protocol::UDP, 127.0.0.1, 12345, false)) {qDebug() TCP Client initialized.;}else{qDebug() TCP Client fail.;}socketManager-setMessageCallback([](const QByteArray message) {qDebug() Received message: message;}); 创建回调函数 收到消息通过回调函数的方式来接收数据 socketManager-setMessageCallback([](const QByteArray message) {qDebug() Received message: message;}); 最后我将项目放到GithubGitHub - xiugou798/QT6-Socket-Demo欢迎大家优化修改
http://www.dnsts.com.cn/news/112864.html

相关文章:

  • 网站后台数据库丢失新手做网站遇到的问题以及解决方案
  • 网站重构工程师深圳创业补贴
  • 丰城市城乡规划建设局网站西安网址
  • 网站策划包括哪些内容wordpress注册不上
  • 网站建设模板代码下载工业软件开发需要学什么专业
  • 建设网站后如何做后台网站主视觉
  • 建设网站选什么地方的主机王也踏青图是哪一集
  • 深圳工程建设交易服务中心网站直播app下载汅api免费下载
  • 关于校园网站建设的建议宁波seo做排名
  • 网站ui设计要点html5网站链接标签
  • 贵阳做网站设计天津微网站建设
  • 怎样可以做网站网站 展示
  • 怎么做淘宝联盟网站制作互联网推广平台
  • 郑州网站优化_郑州网站推广_河南网站建设公司_seo外包顾问服务中文小说网站建设与维护
  • 12380 举报网站建设网站建设福建
  • 网站页面构架更换网站ico
  • 宜宾移动网站建设大学网页设计与制作教材
  • 数字媒体应用 网站开发新手如何自学编程
  • 合肥做网站工作室重庆免费网站制作
  • 建网页还是网站好重庆住建厅网站官网
  • 北海建设网站wordpress win8 主题下载
  • win2003服务器网站管理工具网站自适应手机怎么
  • seo网站建设是什么意思咸宁做网站哪家好
  • 专业做网站较好的公司广州成都上市设计公司
  • 做视频网站免费观看爱精神文明建设网站
  • 怎样黑公司的网站做国外网站的零售
  • 行业网站模版html5手机 网站
  • 织梦 网站搬家网页设计代码大全下载
  • 东莞市官网网站建设价格wordpress主页视频
  • 设计wordpress页面模板下载地址长春seo搜索排名