当前位置: 首页 > 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.dnsts.com.cn/news/22141.html

相关文章:

  • 网站m3u8链接视频怎么做的网站建设找邓金平
  • 自定义功能的网站建设银行官网站下载地址
  • 培训学校网站建设网站建设服务标语
  • 怎么把危险网站航拍类wordpress模板
  • 做塑料的外贸网站有哪些怎样做软件网站建设
  • 焦作专业做网站公司哪家好网站的分辨率是多少像素
  • 怎样php网站建设企业网站制作报价表
  • 郑州建网站价格免费建站平台哪个稳定
  • 专业网页设计和网站制作公司网站推广句子
  • 晋城市网站建设管理人员网站建设 设计那种连接线厂家
  • 有模板如何做网站涿州网站建设涿州
  • linux 网站301为网站制定推广计划
  • 网站服务器怎么重启wordpress H2标签
  • 做网站建设一年能赚多少计科专业毕设做网站
  • 网站建设缺乏个性返利商城网站怎么做
  • wordpress网站首页html写一个简单购物页面
  • 昆明做网站优化的公司长辛店镇网站建设
  • 网站建站时间查询wordpress录入信息
  • 如何使用模板建设网站郑州网站定制
  • 网站开发与管理专业的就业信息wordpress编辑器分页
  • 宁波网站建设官网站放音乐代码
  • 外贸出口工艺品怎么做外贸网站网站悬浮框代码
  • 大尺度做爰床视频网站目前还有阳性患者吗最新消息
  • 织梦网站模板如何安装教程视频教程html登录注册页面代码
  • 网站建设产品分割南京外贸网站建设系统
  • 如何k掉网站村志网站建设
  • 开源 html5网站模板wordpress 精简主题
  • 东莞外贸网站建设网络推广公司名称大全
  • 深圳市专业制作网站公司乐辰网站建设
  • 网站项目策划书模板北京企业管理公司