void TelnetClient::connectionSuccess() { qDebug() << "Successfull outgoing connection"; _status=1; _connection_tries=0; emit connectedToHost(); }
void SocketTestWindow::on_m_pbConnect_clicked() { QString ip = ui->m_leAddress->text(); quint16 port = ui->m_lePort->text().toInt(); m_tcpEnable = ui->m_rbTcpEnable->isChecked(); m_udpEnable = !m_tcpEnable; if(m_tcpEnable) { m_socketClient = new QTcpSocket(); m_socketClient->connectToHost(ip,port); connect(m_socketClient,SIGNAL(connected()),SLOT(connectedToHost())); } else { m_socketClient = new QUdpSocket(); m_remoteHost = ip; m_remotePort = port; m_socketClient->connectToHost(m_remoteHost,m_remotePort); connect(m_socketClient, SIGNAL(readyRead()), this, SLOT(readyReadMessage())); ui->m_pbConnect->setEnabled(false); ui->m_pbListen->setEnabled(false); ui->m_rbUdpEnable->setEnabled(false); ui->m_rbTcpEnable->setEnabled(false); ui->m_pbDisconnect->setEnabled(true); m_startFlags = true; } m_isServer = false; }
void MumbleClient::connectToServer(QString address, unsigned port) { _telnet->connectHost(address,port); QObject::connect(_telnet,SIGNAL(connectedToHost()),this,SLOT(sendVersion())); QObject::connect(_telnet,SIGNAL(haveMessage(QByteArray)),this,SLOT(processProtoMessage(QByteArray))); QObject::connect(_telnet,SIGNAL(haveUDPData(QByteArray)),this,SLOT(processUDPData(QByteArray))); }
void MainWindow::connectToHost() { this->setWindowTitle("Player2"); socket = new QTcpSocket(this); socket->connectToHost(ui->ipEdit->text(), 5555); ui->connectBox->setEnabled(FALSE); ui->statusBar->showMessage("Connecting to Player1..."); connect(socket, SIGNAL(connected()), this, SLOT(connectedToHost())); }
/** * @brief connectToHost Overridden connectToHost() method to add timeout functionality; * @param host * @param port */ void TimeoutSocket::connectToHostWithTimeout(QString host, quint16 port, quint16 timeout) { this->disconnectFromHost(); close(); connect(mAuthTimeout, SIGNAL(timeout()), this, SLOT(timeoutSlot())); connect(this, SIGNAL(connected()), this, SLOT(connectedToHost())); mAuthTimeout->start(timeout); connectToHost(host, port); }
void MumbleClient::disconnectFromServer() { if(_authenticated) { _telnet->disconnectHost(); QObject::disconnect(_telnet,SIGNAL(connectedToHost()),this,SLOT(sendVersion())); QObject::disconnect(_telnet,SIGNAL(haveMessage(QByteArray)),this,SLOT(processProtoMessage(QByteArray))); QObject::disconnect(_telnet,SIGNAL(haveUDPData(QByteArray)),this,SLOT(processUDPData(QByteArray))); _encryption_set = false; _authenticated = false; _synchronized = false; _session_id = -1; } }
/** * @brief TimeoutSocket::connectedToHost triggered when connected to host. */ void TimeoutSocket::connectedToHost() { disconnect(mAuthTimeout, SIGNAL(timeout()), this, SLOT(timeoutSlot())); disconnect(this, SIGNAL(connected()), this, SLOT(connectedToHost())); mAuthTimeout->stop(); // stop the timeout timer }
void CDatabaseConnectionExtWidget::processConnecting() { ui->lDbConnectionStatus->setText(tr("Подключение...")); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); bool connectingToServer = ui->rbnDbServer->isChecked(); //Флаг, показывающий подключаемся ли мы к серверу или к файлу. QSqlDatabase db = QSqlDatabase::addDatabase(connectingToServer ? "QMYSQL" : "QSQLITE", mConnectionName); if(db.isValid() == false) { QMessageBox::critical(this, tr("Ошибка"), tr("Не найден драйвер базы данных.")); return; } if(connectingToServer) { db.setHostName(ui->cbxDbHost->currentText()); db.setDatabaseName(ui->leDbName->text()); db.setUserName(ui->leDbLogin->text()); db.setPassword(ui->leDbPassword->text()); if(db.hostName().isEmpty()) { ui->lDbConnectionStatus->setText(tr("Укажите хост подключения")); return; } } else //connecting to file { db.setDatabaseName(ui->cbxDbFileName->currentText()); if(db.databaseName().isEmpty()) { ui->lDbConnectionStatus->setText(tr("Файл не выбран")); return; } } if(db.open()) //connection is successfully { mConnected = true; ui->lDbConnectionStatus->setText(tr("Подключение произведено")); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); //кеширование: if(mCache) { if(connectingToServer) { mCache->setValue(INI_CONNECTION_TYPE, "server"); mCache->setValue(INI_LASTSERVER, db.hostName()); if(ui->chbxDbRemember->isChecked()) //Галочка 'Запомнить' { mCache->beginGroup(db.hostName()); mCache->setValue(INI_DBNAME, db.databaseName()); mCache->setValue(INI_LOGIN, db.userName()); mCache->setValue(INI_PASSWORD, Global::crypt(db.password())); mCache->endGroup(); } } else //connecting to file { mCache->setValue(INI_CONNECTION_TYPE, "file"); mCache->setValue(INI_LASTFILE, ui->cbxDbFileName->currentText()); QStringList files = mCache->value(INI_FILES).toStringList(); if(files.contains(ui->cbxDbFileName->currentText()) == false) { files.append(ui->cbxDbFileName->currentText()); mCache->setValue(INI_FILES, files); } } mCache->sync(); } if(!connectingToServer) emit connectedToFile(ui->cbxDbFileName->currentText()); else if(db.databaseName().isEmpty()) emit connectedToHost(); else emit connectedToDatabase(db.databaseName()); } else { ui->lDbConnectionStatus->setText(tr("Ошибка подключения")); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); qDebug("CDataBaseConnectionWidget::on_pbnDbConnect_clicked: error: %d", db.lastError().number()); QString errorText = tr("Не удалось подключиться к базе данных.\n"); switch(db.lastError().number()) { case 1045: errorText += tr("Ошибка аутентификации. Проверьте правильность логина и пароля.\n"); break; case 1044: errorText += tr("Неверно указано имя базы данных.\n"); break; case 2005: errorText += tr("Не удалось найти указанный хост.\n"); break; case -1: errorText += tr("Указанный файл не является базой данных."); break; } if(db.lastError().number() >= 0) errorText += '\n' + db.lastError().text(); QMessageBox::warning(this, tr("Ошибка подключения"), errorText); ui->lDbConnectionStatus->clear(); } }