Ejemplo n.º 1
0
/**
 * @brief SocketThread::run
 */
void SocketThread::run()
{
    std::cout << tr("connect done in thread : 0x%1").arg(QString::number((intptr_t)QThread::currentThreadId(), 16)).toStdString() << std::endl;

    if( !(conn = mysql_init((MYSQL*)NULL))){
      printf("init fail\n");
      exit(1);
    }

    printf("mysql_init success.\n");

    if(!mysql_real_connect(conn, server, user, password, NULL, 3306, NULL, 0)){
      printf("connect error.\n");
      exit(1);
    }

    printf("mysql_real_connect success.\n");

    if(mysql_select_db(conn, database) != 0){
      mysql_close(conn);
      printf("select_db fail.\n");
      exit(1);
    }

	// Connecting the socket signals here to exec the slots in the new thread
	QObject::connect(socket, SIGNAL(frameReceived(QString)), this, SLOT(processMessage(QString)));
	QObject::connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
	QObject::connect(socket, SIGNAL(pong(quint64)), this, SLOT(processPong(quint64)));
	QObject::connect(this, SIGNAL(finished()), this, SLOT(finished()), Qt::DirectConnection);

	// Launch the event loop to exec the slots
	exec();
}
Ejemplo n.º 2
0
void Client::addSocket(QtWebsocket::QWsSocket *socket)
{
    sockets << socket;

    connect(socket, SIGNAL(frameReceived(QString)), this, SLOT(processMessage(QString)));
    connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
    connect(socket, SIGNAL(pong(quint64)), this, SLOT(processPong(quint64)));
}
Ejemplo n.º 3
0
void WebSocketServer::processNewConnection()
{
    QtWebsocket::QWsSocket* clientSocket = server->nextPendingConnection();
    QObject::connect(clientSocket, SIGNAL(frameReceived(QString)), this, SLOT(processMessage(QString)));
    QObject::connect(clientSocket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
    QObject::connect(clientSocket, SIGNAL(pong(quint64)), this, SLOT(processPong(quint64)));
    clients << clientSocket;
    std::cout << tr("Client connected").toStdString() << std::endl;
}
Ejemplo n.º 4
0
void Server::processNewConnection()
{
	QtWebsocket::QWsSocket* clientSocket = server->nextPendingConnection();

	QObject::connect(clientSocket, SIGNAL(frameReceived(QString)), this, SLOT(processMessage(QString)));
	QObject::connect(clientSocket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
	QObject::connect(clientSocket, SIGNAL(pong(quint64)), this, SLOT(processPong(quint64)));

	clients << clientSocket;

	qDebug() << tr("Client connected (%1)").arg(clientSocket->isEncrypted() ? "encrypted" : "not encrypted");
}
Ejemplo n.º 5
0
void SocketThread::run()
{
    std::cout << tr("connect done in thread : 0x%1")
        .arg(QString::number((unsigned int)QThread::currentThreadId(), 16))
        .toStdString() << std::endl;

    // Connecting the socket signals here to exec the slots in the new thread
    QObject::connect(socket, SIGNAL(frameReceived(QString)), this, SLOT(processMessage(QString)));
    QObject::connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
    QObject::connect(socket, SIGNAL(pong(quint64)), this, SLOT(processPong(quint64)));
    QObject::connect(this, SIGNAL(finished()), this, SLOT(finished()), Qt::DirectConnection);

    // Launch the event loop to exec the slots
    exec();
}