// New Connection Signals void WebServer::NewSocketConnection(){ if(!this->hasPendingConnections()){ return; } qDebug() << "New Socket Connection"; if(csock!=0){ qDebug() << " - Placed in queue"; return;} if(idletimer->isActive()){ idletimer->stop(); } csock = this->nextPendingConnection(); connect(csock, SIGNAL(textMessageReceived(const QString&)), this, SLOT(EvaluateMessage(const QString&)) ); connect(csock, SIGNAL(binaryMessageReceived(const QByteArray&)), this, SLOT(EvaluateMessage(const QByteArray&)) ); connect(csock, SIGNAL(aboutToClose()), this, SLOT(SocketClosing()) ); connect(csock, SIGNAL(disconnected()), this, SLOT(NewSocketConnection()) ); if(csock == 0){ qWarning() << " - new connection invalid, skipping..."; QTimer::singleShot(10, this, SLOT(NewSocketConnection())); return; } qDebug() << " - Accepting connection:" << csock->origin(); idletimer->start(); //QTimer::singleShot(0,this, SLOT(EvaluateConnection())); }
WebSocket::WebSocket(QWebSocket *sock, QString ID, AuthorizationManager *auth){ SockID = ID; SockAuthToken.clear(); //nothing set initially SOCKET = sock; SendAppCafeEvents = false; AUTHSYSTEM = auth; idletimer = new QTimer(this); idletimer->setInterval(600000); //10-minute timeout idletimer->setSingleShot(true); connect(idletimer, SIGNAL(timeout()), this, SLOT(checkIdle()) ); connect(SOCKET, SIGNAL(textMessageReceived(const QString&)), this, SLOT(EvaluateMessage(const QString&)) ); connect(SOCKET, SIGNAL(binaryMessageReceived(const QByteArray&)), this, SLOT(EvaluateMessage(const QByteArray&)) ); connect(SOCKET, SIGNAL(aboutToClose()), this, SLOT(SocketClosing()) ); idletimer->start(); }
WebSocket::WebSocket(QWebSocket *sock, QString ID, AuthorizationManager *auth){ SockID = ID; SockAuthToken.clear(); //nothing set initially SOCKET = sock; TSOCKET = 0; AUTHSYSTEM = auth; SockPeerIP = SOCKET->peerAddress().toString(); LogManager::log(LogManager::HOST,"New Connection: "+SockPeerIP); idletimer = new QTimer(this); idletimer->setInterval(IDLETIMEOUTMINS*60000); //connection timout for idle sockets idletimer->setSingleShot(true); connect(idletimer, SIGNAL(timeout()), this, SLOT(checkIdle()) ); connect(SOCKET, SIGNAL(textMessageReceived(const QString&)), this, SLOT(EvaluateMessage(const QString&)) ); connect(SOCKET, SIGNAL(binaryMessageReceived(const QByteArray&)), this, SLOT(EvaluateMessage(const QByteArray&)) ); connect(SOCKET, SIGNAL(aboutToClose()), this, SLOT(SocketClosing()) ); idletimer->start(); }
WebSocket::WebSocket(QSslSocket *sock, QString ID, AuthorizationManager *auth){ SockID = ID; SockAuthToken.clear(); //nothing set initially TSOCKET = sock; SOCKET = 0; SockPeerIP = TSOCKET->peerAddress().toString(); LogManager::log(LogManager::HOST,"New Connection: "+SockPeerIP); AUTHSYSTEM = auth; idletimer = new QTimer(this); idletimer->setInterval(IDLETIMEOUTMINS*60000); //connection timout for idle sockets idletimer->setSingleShot(true); connect(idletimer, SIGNAL(timeout()), this, SLOT(checkIdle()) ); connect(TSOCKET, SIGNAL(readyRead()), this, SLOT(EvaluateTcpMessage()) ); connect(TSOCKET, SIGNAL(aboutToClose()), this, SLOT(SocketClosing()) ); connect(TSOCKET, SIGNAL(encrypted()), this, SLOT(nowEncrypted()) ); connect(TSOCKET, SIGNAL(peerVerifyError(const QSslError &)), this, SLOT(peerError(const QSslError &)) ); connect(TSOCKET, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(SslError(const QList<QSslError> &)) ); //qDebug() << " - Starting Server Encryption Handshake"; TSOCKET->startServerEncryption(); //qDebug() << " - Socket Encrypted:" << TSOCKET->isEncrypted(); idletimer->start(); }