12345678910111213141516171819202122232425262728293031323334353637383940 |
- #include "client.h"
- client::client(QObject *parent, QUrl url) : QObject(parent)
- {
- qDebug() << "WebSocket server:" << url;
- m_url = url;
- connect(&m_webSocket, &QWebSocket::connected, this, &client::onConnected);
- connect(&m_webSocket, &QWebSocket::disconnected, this, &client::closed);
- m_webSocket.open(m_url);
- }
- void client::SlotSendStyleToSim(QString newstyle)
- {
- msg = newstyle;
- m_webSocket.sendTextMessage(msg);
- }
- void client::onConnected()
- {
- qDebug() << "WebSocket connected";
- connect(&m_webSocket, &QWebSocket::textMessageReceived,
- this, &client::onTextMessageReceived);
- // m_webSocket.sendTextMessage(msg);
- }
- void client::onTextMessageReceived(QString message)
- {
- qDebug() << "Message received:" << message;
- bool *ok = new bool();
- int msg = message.toInt(ok);
- if (ok)
- {
- if (msg == 111)
- {
- qDebug()<<QString::fromLocal8Bit("收到应答");
- }
- }
- delete ok;
- // m_webSocket.close();
- }
|