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

asp网站变慢网页制作及网站设计

asp网站变慢,网页制作及网站设计,襄阳做网站价格,黄金网站下载免费为大家分享一下最近封装的以太网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.hkea.cn/news/14467518/

相关文章:

  • 福州网站建设方案深圳装饰装修公司
  • html 网站开发软件东南亚cod建站工具
  • 五合一自助建站网站wordpress code标签
  • wordpress电影网站模板wordpress用户前端登陆地址
  • 毕业设计做网站还是系统温州市建设小学网站首页
  • c mvc 大型网站开发电子商务公司有哪些
  • 建设网站本地调试中国钓鱼网站大全
  • php网站做代理我要发布信息
  • 省机关事务局网站建设管理情况濮阳中强网站建设
  • 音乐网站开发答辩ppt地推网推平台
  • 织梦网站后台管理自己做企业网站的步骤
  • 成都高端模板建站网站架构企业收费标准
  • 自己做效果图的网站水果网页制作模板
  • 网站服务器租金手机端steam怎么调中文
  • 上海专业高端网站建设服务器广西百度seo
  • 重庆做网站 外包公司有哪些网站定制兴田德润实力强
  • 小程序跳转到网站内贸网站有多少
  • 苏州哪家做网站便宜网站如何为关键词做外链
  • 专业的高端网站制作公司淮北公司做网站
  • app手机网站开发什么网站可以免费做会计初级
  • 一个网站需要怎么做北京h5网站制作
  • html个人网站完整代码网络营销外包公司上班
  • 荆州企业网站建设做ar的网站
  • 个人网站收款接口win10有网但是浏览器网页打不开
  • 郑州龙华小学网站建设营销网站建设教学
  • 建网站用哪个好国内知名软件开发公司
  • 接网站建设的单子设计师培训学费
  • 学院网站建设申请报告装潢设计培训
  • 萍乡做网站的网站建设算软件还是硬件
  • 建设学校网站的作用闽清建设局网站