void WebUser::setSocket(QWebSocket *socket) { socket_ = socket; connect(socket_, SIGNAL(connected()), SIGNAL(connected())); connect(socket_, SIGNAL(disconnected()), SIGNAL(disconnected())); connect(socket_, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(onSocketError(QAbstractSocket::SocketError))); connect(socket_, SIGNAL(textMessageReceived(QString)), SLOT(onSocketTextMessageReceived(QString))); }
WebSocketQt::~WebSocketQt() { disconnect(_socket, SIGNAL(connected()), this, SLOT(connected())); disconnect(_socket, SIGNAL(disconnected()), this, SLOT(disconnected())); disconnect(_socket, SIGNAL(textMessageReceived(QString)), this, SLOT(textMessageReceived(QString))); disconnect(_socket, SIGNAL(binaryMessageReceived(QByteArray)), this, SLOT(binaryMessageReceived(QByteArray))); disconnect(_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error(QAbstractSocket::SocketError))); _socket->close(); delete _socket; }
WebSocketQt::WebSocketQt(ClassMethodWrapper<Client, void(Client::*)(Responce*), Responce> * processMethod) : QObject(), Transport(processMethod), _socket(new QWebSocket(QString(""), QWebSocketProtocol::Version13, this)) { Q_CHECK_PTR(_socket); connect(_socket, SIGNAL(connected()), this, SLOT(connected())); connect(_socket, SIGNAL(disconnected()), this, SLOT(disconnected())); connect(_socket, SIGNAL(textMessageReceived(QString)), this, SLOT(textMessageReceived(QString))); connect(_socket, SIGNAL(binaryMessageReceived(QByteArray)), this, SLOT(binaryMessageReceived(QByteArray))); connect(_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error(QAbstractSocket::SocketError))); _tickTimer.start(200, this); }
Connector::Connector(QObject *parent) : QObject(parent) { connect(&cliSocket, SIGNAL(connected()), this, SLOT(onConnected())); connect(&cliSocket, SIGNAL(disconnected()), this, SLOT(onDisconnected())); connect(&cliSocket, SIGNAL(textMessageReceived(QString)), this, SLOT(onTextMsg(QString))); }
SocketIOClient::SocketIOClient(QObject *parent) : QObject(parent), m_pWebSocket(0), m_pNetworkAccessManager(0), m_requestUrl(), m_mustMask(true), m_connectionTimeout(30000), m_heartBeatTimeout(20000), m_pHeartBeatTimer(0), m_sessionId() { m_pWebSocket = new QWebSocket(QString(), QWebSocketProtocol::V_LATEST, this); m_pNetworkAccessManager = new QNetworkAccessManager(this); m_pHeartBeatTimer = new QTimer(this); m_pHeartBeatTimer->setInterval(m_heartBeatTimeout); connect(m_pWebSocket, SIGNAL(connected()), this,SLOT(onConnected())); connect(m_pWebSocket, SIGNAL(disconnected()), this, SLOT(onDisconnected())); connect(m_pWebSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onError(QAbstractSocket::SocketError))); connect(m_pWebSocket, SIGNAL(textMessageReceived(QString)), this, SLOT(onTextMessage(QString))); connect(m_pWebSocket, SIGNAL(binaryMessageReceived(QByteArray)), this, SLOT(onBinaryMessage(QByteArray))); connect(m_pNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*))); connect(m_pHeartBeatTimer, SIGNAL(timeout()), this, SLOT(sendHeartBeat())); //socket.io connections connect(this, SIGNAL(handshakeSucceeded()), this, SLOT(onHandshakeSucceeded())); //socket.io test connections connect(this, SIGNAL(heartbeatReceived()), this, SLOT(onHeartbeatReceived())); }
void InterfaceHttp::webSocketsNewConnection() { WebSocket *webSocket = webSocketServer->nextPendingConnection(); connect(webSocket, SIGNAL(textMessageReceived(QString)), SLOT(webSocketsProcessMessage(QString))); connect(webSocket, SIGNAL(binaryMessageReceived(QByteArray)), SLOT(webSocketsProcessBinaryMessage(QByteArray))); connect(webSocket, SIGNAL(disconnected()), SLOT(webSocketsSocketDisconnected())); webSocketClients << webSocket; webSocketsUpdateConnectedClients(); }
//! [onNewConnection] void ChatServer::onNewConnection() { QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection(); connect(pSocket, SIGNAL(textMessageReceived(QString)), this, SLOT(processMessage(QString))); connect(pSocket, SIGNAL(disconnected()), this, SLOT(socketDisconnected())); m_clients << pSocket; }
//! [onNewConnection] void EchoServer::onNewConnection() { WebSocket *pSocket = m_pWebSocketServer->nextPendingConnection(); connect(pSocket, SIGNAL(textMessageReceived(QString)), this, SLOT(processMessage(QString))); connect(pSocket, SIGNAL(binaryMessageReceived(QByteArray)), this, SLOT(processBinaryMessage(QByteArray))); connect(pSocket, SIGNAL(disconnected()), this, SLOT(socketDisconnected())); //connect(pSocket, SIGNAL(pong(quint64)), this, SLOT(processPong(quint64))); m_clients << pSocket; }
/*! * \internal */ void WebSocket::makeConnections(const QTcpSocket *pTcpSocket) { //pass through signals connect(pTcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SIGNAL(error(QAbstractSocket::SocketError))); connect(pTcpSocket, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *)), this, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *))); connect(pTcpSocket, SIGNAL(readChannelFinished()), this, SIGNAL(readChannelFinished())); //connect(pTcpSocket, SIGNAL(aboutToClose()), this, SIGNAL(aboutToClose())); //connect(pTcpSocket, SIGNAL(bytesWritten(qint64)), this, SIGNAL(bytesWritten(qint64))); //catch signals connect(pTcpSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(processStateChanged(QAbstractSocket::SocketState))); connect(pTcpSocket, SIGNAL(readyRead()), this, SLOT(processData())); connect(&m_dataProcessor, SIGNAL(controlFrameReceived(WebSocketProtocol::OpCode, QByteArray)), this, SLOT(processControlFrame(WebSocketProtocol::OpCode, QByteArray))); connect(&m_dataProcessor, SIGNAL(textFrameReceived(QString,bool)), this, SIGNAL(textFrameReceived(QString,bool))); connect(&m_dataProcessor, SIGNAL(binaryFrameReceived(QByteArray,bool)), this, SIGNAL(binaryFrameReceived(QByteArray,bool))); connect(&m_dataProcessor, SIGNAL(binaryMessageReceived(QByteArray)), this, SIGNAL(binaryMessageReceived(QByteArray))); connect(&m_dataProcessor, SIGNAL(textMessageReceived(QString)), this, SIGNAL(textMessageReceived(QString))); connect(&m_dataProcessor, SIGNAL(errorEncountered(WebSocketProtocol::CloseCode,QString)), this, SLOT(close(WebSocketProtocol::CloseCode,QString))); }
//! [onNewConnection] void SslEchoServer::onNewConnection() { QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection(); qDebug() << "Client connected:" << pSocket->peerName() << pSocket->origin(); connect(pSocket, SIGNAL(textMessageReceived(QString)), this, SLOT(processMessage(QString))); connect(pSocket, SIGNAL(binaryMessageReceived(QByteArray)), this, SLOT(processBinaryMessage(QByteArray))); connect(pSocket, SIGNAL(disconnected()), this, SLOT(socketDisconnected())); //connect(pSocket, SIGNAL(pong(quint64)), this, SLOT(processPong(quint64))); m_clients << pSocket; }
FayeConnector::FayeConnector(QObject *parent) : QObject(parent), clientId("") { //Initializing websocket faye = new QWebSocket(); //Connecting websocket signals to slots QObject::connect(faye, SIGNAL(connected()), this, SLOT(communicationOpened())); QObject::connect(faye, SIGNAL(disconnected()), this, SLOT(communicationClosed())); QObject::connect(faye, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error(QAbstractSocket::SocketError))); QObject::connect(faye, SIGNAL(textMessageReceived(QString)), this, SLOT(message(QString))); status = NA; emit statusChanged(NA); }
// ===================================================================== // QWebSocket // ===================================================================== void CWebSocketServer::onNewConnection() { qDebug() << "CWebSocketServer : New Connection"; QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection(); if (!pSocket) return; m_clients.insert(pSocket, m_client_count); m_clients_rev.insert(m_client_count, pSocket); connect(pSocket, SIGNAL(textMessageReceived(QString)), this, SLOT(processMessage(QString))); connect(pSocket, SIGNAL(binaryMessageReceived(QByteArray)), this, SLOT(processMessage(QByteArray))); connect(pSocket, SIGNAL(disconnected()), this, SLOT(socketDisconnected())); emit connected(m_client_count); m_client_count++; }
SpotifyIO::SpotifyIO(QObject *parent) : QObject(parent) { nam = new QNetworkAccessManager(this); ws = new QWebSocket(origin, QWebSocketProtocol::VersionLatest, this); mediaPlayer = new MediaPlayer(this); QObject::connect(ws, SIGNAL(connected()), this, SLOT(onConnected())); QObject::connect(ws, SIGNAL(disconnected()), this, SLOT(onDisconnected())); QObject::connect(ws, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(onStateChanged(QAbstractSocket::SocketState))); QObject::connect(ws, SIGNAL(textMessageReceived(QString)), this, SLOT(onTextMessageReceived(QString))); QObject::connect(ws, SIGNAL(binaryMessageReceived(QByteArray)), this, SLOT(onBinaryMessageReceived(QByteArray))); QObject::connect(ws, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onError(QAbstractSocket::SocketError))); QObject::connect(ws, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(onSslErrors(QList<QSslError>))); heartbeat = new QTimer(this); heartbeat->setInterval(3 * 60 * 1000); QObject::connect(heartbeat, SIGNAL(timeout()), this, SLOT(onHeartbeat())); _state = DisconnectedState; Q_EMIT stateChanged(); }
CloudConnection::CloudConnection(const QUrl &authenticationServer, const QUrl &proxyServer, QObject *parent) : QObject(parent), m_authenticationServerUrl(authenticationServer), m_proxyServerUrl(proxyServer), m_connected(false), m_error(Cloud::CloudErrorNoError) { m_reconnectionTimer = new QTimer(this); m_reconnectionTimer->setSingleShot(false); connect(m_reconnectionTimer, &QTimer::timeout, this, &CloudConnection::reconnectionTimeout); m_connection = new QWebSocket("guhd", QWebSocketProtocol::Version13, this); connect(m_connection, SIGNAL(connected()), this, SLOT(onConnected())); connect(m_connection, SIGNAL(disconnected()), this, SLOT(onDisconnected())); connect(m_connection, SIGNAL(textMessageReceived(QString)), this, SLOT(onTextMessageReceived(QString))); connect(m_connection, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onError(QAbstractSocket::SocketError))); m_authenticator = new CloudAuthenticator("0631d42ba0464e4ebd4b78b15c53f532", "b7919ebf3bcf48239f348e764744079b", this); m_authenticator->setUrl(m_authenticationServerUrl); connect(m_authenticator, &CloudAuthenticator::authenticationChanged, this, &CloudConnection::onAuthenticationChanged); }
/*! \internal */ void QWebSocketDataProcessor::process(QIODevice *pIoDevice) { bool isDone = false; while (!isDone) { QWebSocketFrame frame = QWebSocketFrame::readFrame(pIoDevice); if (Q_LIKELY(frame.isValid())) { if (frame.isControlFrame()) { isDone = processControlFrame(frame); } else { //we have a dataframe; opcode can be OC_CONTINUE, OC_TEXT or OC_BINARY if (Q_UNLIKELY(!m_isFragmented && frame.isContinuationFrame())) { clear(); Q_EMIT errorEncountered(QWebSocketProtocol::CloseCodeProtocolError, tr("Received Continuation frame, while there is " \ "nothing to continue.")); return; } if (Q_UNLIKELY(m_isFragmented && frame.isDataFrame() && !frame.isContinuationFrame())) { clear(); Q_EMIT errorEncountered(QWebSocketProtocol::CloseCodeProtocolError, tr("All data frames after the initial data frame " \ "must have opcode 0 (continuation).")); return; } if (!frame.isContinuationFrame()) { m_opCode = frame.opCode(); m_isFragmented = !frame.isFinalFrame(); } quint64 messageLength = (quint64)(m_opCode == QWebSocketProtocol::OpCodeText) ? m_textMessage.length() : m_binaryMessage.length(); if (Q_UNLIKELY((messageLength + quint64(frame.payload().length())) > MAX_MESSAGE_SIZE_IN_BYTES)) { clear(); Q_EMIT errorEncountered(QWebSocketProtocol::CloseCodeTooMuchData, tr("Received message is too big.")); return; } if (m_opCode == QWebSocketProtocol::OpCodeText) { QString frameTxt = m_pTextCodec->toUnicode(frame.payload().constData(), frame.payload().size(), m_pConverterState); bool failed = (m_pConverterState->invalidChars != 0) || (frame.isFinalFrame() && (m_pConverterState->remainingChars != 0)); if (Q_UNLIKELY(failed)) { clear(); Q_EMIT errorEncountered(QWebSocketProtocol::CloseCodeWrongDatatype, tr("Invalid UTF-8 code encountered.")); return; } else { m_textMessage.append(frameTxt); Q_EMIT textFrameReceived(frameTxt, frame.isFinalFrame()); } } else { m_binaryMessage.append(frame.payload()); Q_EMIT binaryFrameReceived(frame.payload(), frame.isFinalFrame()); } if (frame.isFinalFrame()) { if (m_opCode == QWebSocketProtocol::OpCodeText) Q_EMIT textMessageReceived(m_textMessage); else Q_EMIT binaryMessageReceived(m_binaryMessage); clear(); isDone = true; } } } else { Q_EMIT errorEncountered(frame.closeCode(), frame.closeReason()); clear(); isDone = true; } } }
void QPushbulletHandler::webSocketConnected() { qDebug() << "Web Socket Connected"; connect(&m_WebSocket, SIGNAL(textMessageReceived(QString)), this, SLOT(textMessageReceived(QString))); }