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

商业网站 模板wordpress 标题入库

商业网站 模板,wordpress 标题入库,谷歌关键词排名查询,网站建设费用主要包括那几项websocket 是基于 TCP socket 之上的应用层#xff0c; 解决 HTML 轮询连接的问题#xff0c;实现客户端与服务端长连接#xff0c; 实现消息互相发送#xff0c;全双工。 服务端#xff0c; 使用 QT 教程demo chatserver.h #ifndef CHATSERVER_H #define CHATSERVER_H#i…websocket 是基于 TCP socket 之上的应用层 解决 HTML 轮询连接的问题实现客户端与服务端长连接 实现消息互相发送全双工。 服务端 使用 QT 教程demo chatserver.h #ifndef CHATSERVER_H #define CHATSERVER_H#include QtCore/QObject #include QtCore/QListQT_FORWARD_DECLARE_CLASS(QWebSocketServer) QT_FORWARD_DECLARE_CLASS(QWebSocket) QT_FORWARD_DECLARE_CLASS(QString)class ChatServer : public QObject {Q_OBJECT public:explicit ChatServer(quint16 port, QObject *parent nullptr);~ChatServer() override;private slots:void onNewConnection();void processMessage(const QString message);void socketDisconnected();private:QWebSocketServer *m_pWebSocketServer;QListQWebSocket * m_clients; };#endif //CHATSERVER_H chatserver.cpp /**************************************************************************** ** ** Copyright (C) 2016 Kurt Pattyn pattyn.kurtgmail.com. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWebSockets module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** BSD License Usage ** Alternatively, you may use this file under the terms of the BSD license ** as follows: ** ** Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are ** met: ** * Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. ** * Neither the name of The Qt Company Ltd nor the names of its ** contributors may be used to endorse or promote products derived ** from this software without specific prior written permission. ** ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include chatserver.h#include QtWebSockets #include QtCore#include cstdio using namespace std;QT_USE_NAMESPACEstatic QString getIdentifier(QWebSocket *peer) {return QStringLiteral(%1:%2).arg(peer-peerAddress().toString(),QString::number(peer-peerPort())); }//! [constructor] ChatServer::ChatServer(quint16 port, QObject *parent) :QObject(parent),m_pWebSocketServer(new QWebSocketServer(QStringLiteral(Chat Server),QWebSocketServer::NonSecureMode,this)) {if (m_pWebSocketServer-listen(QHostAddress::Any, port)){QTextStream(stdout) Chat Server listening on port port \n;connect(m_pWebSocketServer, QWebSocketServer::newConnection,this, ChatServer::onNewConnection);} }ChatServer::~ChatServer() {m_pWebSocketServer-close(); } //! [constructor]//! [onNewConnection] void ChatServer::onNewConnection() {auto pSocket m_pWebSocketServer-nextPendingConnection();QTextStream(stdout) getIdentifier(pSocket) connected!\n;pSocket-setParent(this);// 对连接进来的每一个进行信号槽连接绑定connect(pSocket, QWebSocket::textMessageReceived,this, ChatServer::processMessage);connect(pSocket, QWebSocket::disconnected,this, ChatServer::socketDisconnected);// 使用 list 进行管理方便断开m_clients pSocket; } //! [onNewConnection]//! [processMessage] void ChatServer::processMessage(const QString message) {QWebSocket *pSender qobject_castQWebSocket *(sender());for (QWebSocket *pClient : qAsConst(m_clients)) {if (pClient pSender) //dont echo message back to sender{pClient-sendTextMessage(message host echo );qDebug() peer address pClient-peerAddress();}}QTextStream(stdout) received msg: message std::endl; } //! [processMessage]//! [socketDisconnected] void ChatServer::socketDisconnected() {QWebSocket *pClient qobject_castQWebSocket *(sender());QTextStream(stdout) getIdentifier(pClient) disconnected!\n;if (pClient){m_clients.removeAll(pClient);pClient-deleteLater();} } //! [socketDisconnected] main.cpp #include QtCore/QCoreApplication#include chatserver.hint main(int argc, char *argv[]) {QCoreApplication a(argc, argv);ChatServer server(1234);return a.exec(); }客户端 clientwidget.h #ifndef CLIENTWIDGET_H #define CLIENTWIDGET_H#include QWidget #include WebsocketClient.hQT_FORWARD_DECLARE_CLASS(QWebSocketClient) QT_FORWARD_DECLARE_CLASS(QWebSocket)namespace Ui { class ClientWidget; }class ClientWidget : public QWidget {Q_OBJECTpublic:explicit ClientWidget(QWidget *parent 0);~ClientWidget();private slots:void on_pushButton_clicked();void on_pushButton_2_clicked();void slot_recvMsg(QString msg);private:Ui::ClientWidget *ui;WebsocketClient m_client; };#endif // CLIENTWIDGET_H clientwidget.cpp #include ClientWidget.h #include ui_ClientWidgetwidget.hClientWidget::ClientWidget(QWidget *parent) :QWidget(parent),ui(new Ui::ClientWidget) {ui-setupUi(this);}ClientWidget::~ClientWidget() {delete ui; }void ClientWidget::on_pushButton_clicked() {m_client.connectToServer();connect(m_client, WebsocketClient::sig_newMsg, this, ClientWidget::slot_recvMsg); }void ClientWidget::on_pushButton_2_clicked() {m_client.sendMsg(ui-lineEditSendTxt-text()); }void ClientWidget::slot_recvMsg(QString msg) {ui-textBrowserRecv-append(msg); } websocketclient.h #ifndef WEBSOCKETCLIENT_H #define WEBSOCKETCLIENT_H#include QDebug #include QWebSocket QT_FORWARD_DECLARE_CLASS(QWebSocketClient) QT_FORWARD_DECLARE_CLASS(QWebSocket)class WebsocketClient:public QObject {Q_OBJECT public:WebsocketClient();//connect to servervoid connectToServer();bool sendMsg(QString msg);void disConnect();public slots:void slot_recvMsg(QString msg);signals:void sig_newMsg(QString msg);private:QWebSocket m_clientSocket; };#endif // WEBSOCKETCLIENT_H websocketclient.cpp #include WebsocketClient.hWebsocketClient::WebsocketClient() {}void WebsocketClient::connectToServer() {QString urlStr ws://127.0.0.1:1234;m_clientSocket.open(QUrl(urlStr));connect(m_clientSocket, QWebSocket::textMessageReceived, this, WebsocketClient::slot_recvMsg); }bool WebsocketClient::sendMsg(QString msg) {if (m_clientSocket.sendTextMessage(msg)) {return true;}else {return false;} }void WebsocketClient::disConnect() {m_clientSocket.close(); }void WebsocketClient::slot_recvMsg(QString msg) {qDebug() client received from host: msg;emit sig_newMsg(msg); }
http://www.huolong8.cn/news/265962/

相关文章:

  • 咸阳市城乡建设规划局网站专业网站制作哪家强
  • 网站推广存在的问题有了php源码怎么做网站
  • 网站后台怎么更新中国建设银行个人网上银行登录
  • 中山企业网站建设公司邯郸房产信息网查询系统
  • 做视频网站带宽要求江门seo咨询
  • 骏驰网站建设用python做的大型网站
  • 衡阳建设学校官方网站wordpress 扫码支付宝
  • 不懂编程如何做网站梅林网站建设公司
  • 石家庄网站开发免费购物网站系统
  • 做旅游网站需要的背景大型企业网站建设制作
  • 做网站还要做点手机吗成都医疗seo整站优化
  • 旅游网站组织结构图怎么做甘肃省城乡建设局网站首页
  • 门户网站建设采购纸箱 技术支持 东莞网站建设
  • 企业网站备案要关站吗WordPress任务悬赏插件
  • 外贸网站建设需大资讯wordpress主题
  • 邯郸网站制作个人小说网站的图片长图怎么做的
  • 广东网站设计有名的公司宿州推广公司
  • 仿朋友圈网站建设巴中微小网站建设案例
  • 俄罗斯国际空间站备案查询网站
  • 仿笑话网站源码企业模板网站建设
  • 如何免费建立自己的网站网络平台维护
  • 铜川做网站的公司济南源聚网络公司
  • 做策划有帮助的网站建设礼品网站的策划书
  • 个人域名做企业网站自己做外贸自己做网站
  • 新闻录入网站模板wordpress在线
  • 新加坡房产网站大全关于营销策划的方案
  • 腾讯网网站网址网站开发分几种类型
  • 建设网站需要多少时间南庄顺德网站建设
  • 做网站应达到什么效果餐饮网站建设规划书
  • 网站与经营网站网站关键词优化的步骤