void jConnection::setSocket(QTcpSocket *socket) { m_socket = socket; QObject::connect(m_socket,SIGNAL(connected()),this,SLOT(connected())); QObject::connect(m_socket,SIGNAL(disconnected()),this,SLOT(disconnected())); QObject::connect(m_socket,SIGNAL(hostFound()),this,SLOT(hostFound())); QObject::connect(m_socket,SIGNAL(readyRead()),this,SLOT(read())); QObject::connect(m_socket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(error(QAbstractSocket::SocketError))); QObject::connect(m_socket,SIGNAL(stateChanged(QAbstractSocket::SocketState)),this,SLOT(stateChanged(QAbstractSocket::SocketState))); }
FQTermTelnetSocket::FQTermTelnetSocket() : FQTermSocket() { private_socket_ = new FQTermSocketPrivate(); FQ_VERIFY(connect(private_socket_, SIGNAL(connected()), this, SIGNAL(connected()))); FQ_VERIFY(connect(private_socket_, SIGNAL(hostFound()), this, SIGNAL(hostFound()))); FQ_VERIFY(connect(private_socket_, SIGNAL(connectionClosed()), this, SIGNAL(connectionClosed()))); FQ_VERIFY(connect(private_socket_, SIGNAL(delayedCloseFinished()), this, SIGNAL(delayedCloseFinished()))); FQ_VERIFY(connect(private_socket_, SIGNAL(readyRead()), this, SIGNAL(readyRead()))); FQ_VERIFY(connect(private_socket_, SIGNAL(error(QAbstractSocket::SocketError)), this, SIGNAL(error(QAbstractSocket::SocketError)))); FQ_VERIFY(connect(private_socket_, SIGNAL(socketState(int)), this, SIGNAL(socketState(int)))); }
Http::Http() : QNetworkProtocol(), connectionReady( FALSE ) { commandSocket = new QSocket( this ); connect( commandSocket, SIGNAL( hostFound() ), this, SLOT( hostFound() ) ); connect( commandSocket, SIGNAL( connected() ), this, SLOT( connected() ) ); connect( commandSocket, SIGNAL( connectionClosed() ), this, SLOT( closed() ) ); connect( commandSocket, SIGNAL( readyRead() ), this, SLOT( readyRead() ) ); }
void QMyServer::_connectSocketSignals () { connect(socket, SIGNAL(encrypted()), this, SLOT(slot_encrypted())); connect(socket, SIGNAL(encryptedBytesWritten(qint64)), this, SLOT(slot_encryptedBytesWritten(qint64))); connect(socket, SIGNAL(modeChanged(QSslSocket::SslMode)), this, SLOT(slot_modeChanged(QSslSocket::SslMode))); connect(socket, SIGNAL(peerVerifyError(const QSslError &)), this, SLOT(slot_peerVerifyError (const QSslError &))); connect(socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(slot_sslErrors(const QList<QSslError> &))); connect(socket, SIGNAL(readyRead()), this, SLOT(slot_readyRead())); connect(socket, SIGNAL(connected()), this, SLOT(slot_connected())); connect(socket, SIGNAL(disconnected()), this, SLOT(slot_disconnected())); connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slot_error(QAbstractSocket::SocketError))); connect(socket, SIGNAL(hostFound()), this, SLOT(slot_hostFound())); connect(socket, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *)), this, SLOT(slot_proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *))); connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(slot_stateChanged(QAbstractSocket::SocketState))); }
void AbstractSocket::connectPrivateSignals() { // Used to manage socket expiration timeout // Expiration delay is reinit when a bytes is writted connect(this, SIGNAL(bytesWritten(qint64)), this, SLOT(onBytesWritten(qint64))); // Used to manage socket expiration timeout // Expiration delay is reinit when data are available is read connect(this, SIGNAL(readyRead()), this, SLOT(onReadyRead())); // Those next signals are used as debug, for now connect(this, SIGNAL(connected()), this, SLOT(onConnected())); connect(this, SIGNAL(disconnected()), this, SLOT(onDisconnected())); connect(this, SIGNAL(error ( QAbstractSocket::SocketError)), this, SLOT(onError ( QAbstractSocket::SocketError))); connect(this, SIGNAL(hostFound ()), this, SLOT(onHostFound ())); connect(this, SIGNAL(proxyAuthenticationRequired ( const QNetworkProxy &, QAuthenticator *)), this, SLOT(onProxyAuthenticationRequired ( const QNetworkProxy &, QAuthenticator *))); connect(this, SIGNAL(stateChanged (QAbstractSocket::SocketState)), this, SLOT(onStateChanged (QAbstractSocket::SocketState))); connect(this, SIGNAL(aboutToClose()), this, SLOT(onAboutToClose())); connect(this, SIGNAL(readChannelFinished()), this, SLOT(onReadChannelFinished())); }
QmvHttp::QmvHttp() : QNetworkProtocol(), connectionReady( FALSE ) { #ifdef QMVHTTP_DEBUG qDebug("QmvHttp::QmvHttp"); #endif commandSocket = new QSocket( this ); connect( commandSocket, SIGNAL( hostFound() ), this, SLOT( hostFound() ) ); connect( commandSocket, SIGNAL( connected() ), this, SLOT( connected() ) ); connect( commandSocket, SIGNAL( connectionClosed() ), this, SLOT( closed() ) ); connect( commandSocket, SIGNAL( readyRead() ), this, SLOT( readyRead() ) ); }
Nntp::Nntp() : QNetworkProtocol(), connectionReady( FALSE ), readGroups( FALSE ), readArticle( FALSE ) { // create the command socket and connect to its signals commandSocket = new QSocket( this ); connect( commandSocket, SIGNAL( hostFound() ), this, SLOT( hostFound() ) ); connect( commandSocket, SIGNAL( connected() ), this, SLOT( connected() ) ); connect( commandSocket, SIGNAL( connectionClosed() ), this, SLOT( closed() ) ); connect( commandSocket, SIGNAL( readyRead() ), this, SLOT( readyRead() ) ); connect( commandSocket, SIGNAL( error( int ) ), this, SLOT( error( int ) ) ); }
Client::Client() : QObject(0), qout(stdout), tcpSocket(NULL), shutdownRequested(false) { tcpSocket = new QTcpSocket(this); Q_ASSERT(connect(tcpSocket, SIGNAL(hostFound()), this, SLOT(OnHostFound()))); Q_ASSERT(connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(ProcessRequest()))); Q_ASSERT(connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(DisplayError(QAbstractSocket::SocketError)))); }
void FtpClient::init() { qDebug() << "FtpClient:: " << port << " Init"; // if we did not find one, use IPv4 localhost if (ipAddress.isEmpty()) ipAddress = QHostAddress(QHostAddress::LocalHost).toString(); qDebug() << "FtpClient:: " << port << " Init connect"; // from abtractsocket connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(handleError(QAbstractSocket::SocketError))); connect(tcpSocket, SIGNAL(connected()), this, SLOT(handleConnected())); connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(handleDisconnected())); connect(tcpSocket, SIGNAL(hostFound()), this, SLOT(handleHostFound())); connect(tcpSocket, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&,QAuthenticator*)), this, SLOT(handleProxyAuthenticationRequired(const QNetworkProxy&,QAuthenticator*))); connect(tcpSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(handleStateChanged(QAbstractSocket::SocketState))); // from QIODevice connect(tcpSocket, SIGNAL(aboutToClose()), this, SLOT(handleAboutToClose())); connect(tcpSocket, SIGNAL(bytesWritten(qint64)), this, SLOT(handleBytesWritten(qint64))); connect(tcpSocket, SIGNAL(readChannelFinished()), this, SLOT(handleReadChannelFinished())); connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(handleReadyRead())); qDebug() << "FtpClient:: " << port << " Init NetworkConfigurationManager manager"; QNetworkConfigurationManager manager; if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) { qDebug() << "FtpClient::Init QNetworkConfigurationManager::NetworkSessionRequired"; // Get saved network configuration QSettings settings(QSettings::UserScope, QLatin1String(SETTING_STR)); settings.beginGroup(QLatin1String("QtNetwork")); const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString(); settings.endGroup(); // If the saved network configuration is not currently discovered use the system default QNetworkConfiguration config = manager.configurationFromIdentifier(id); if ((config.state() & QNetworkConfiguration::Discovered) != QNetworkConfiguration::Discovered) { config = manager.defaultConfiguration(); } qDebug() << "FtpClient:: " << port << " Init new QNetworkSession(config, this)"; networkSession = new QNetworkSession(config, this); qDebug() << "FtpClient:: " << port << " Init connect(networkSession, SIGNAL(opened()), this, SLOT(handleSessionOpened()))"; connect(networkSession, SIGNAL(opened()), this, SLOT(handleSessionOpened())); qDebug() << "FtpClient:: " << port << " Init networkSession->open()"; networkSession->open(); } else { qDebug() << "FtpClient:: Init " << port << " tcpSocket->connectToHost())" << " ipAddress " << ipAddress << " port " << port; tcpSocket->connectToHost(QHostAddress(ipAddress), port); } mInitiated = true; }
RDSocket::RDSocket(int id,QObject *parent) : Q3Socket(parent) { id_num=id; connect(this,SIGNAL(hostFound()),this,SLOT(hostFoundData())); connect(this,SIGNAL(connected()),this,SLOT(connectedData())); connect(this,SIGNAL(connectionClosed()),this,SLOT(connectionClosedData())); connect(this,SIGNAL(delayedCloseFinished()), this,SLOT(delayedCloseFinishedData())); connect(this,SIGNAL(readyRead()),this,SLOT(readyReadData())); connect(this,SIGNAL(bytesWritten(int)),this,SLOT(bytesWrittenData(int))); connect(this,SIGNAL(error(int)),this,SLOT(errorData(int))); }
bool TCPSendRawNode::initialise() { if( !NodeControlBase::initialise() ) { return( false ); } connect( &mSocket, SIGNAL(connected()), this, SLOT(socketConnected()) ); connect( &mSocket, SIGNAL(disconnected()), this, SLOT(socketDisconnected() ) ); connect( &mSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)) ); connect( &mSocket, SIGNAL(hostFound()), this, SLOT(socketHostFound()) ); return( true ); }
bool KviHttpRequest::doConnect() { m_p->uPort = m_connectionUrl.port(); if(m_p->uPort == 0) m_p->uPort = m_p->bIsSSL ? 443 : 80; if(m_p->pSocket) closeSocket(); #ifdef COMPILE_SSL_SUPPORT m_p->pSocket = m_p->bIsSSL ? new QSslSocket() : new QTcpSocket(); #else m_p->pSocket = new QTcpSocket(); #endif QObject::connect(m_p->pSocket, SIGNAL(connected()), this, SLOT(slotSocketConnected())); QObject::connect(m_p->pSocket, SIGNAL(disconnected()), this, SLOT(slotSocketDisconnected())); QObject::connect(m_p->pSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotSocketError(QAbstractSocket::SocketError))); QObject::connect(m_p->pSocket, SIGNAL(readyRead()), this, SLOT(slotSocketReadDataReady())); QObject::connect(m_p->pSocket, SIGNAL(hostFound()), this, SLOT(slotSocketHostResolved())); emit resolvingHost(m_connectionUrl.host()); #ifdef COMPILE_SSL_SUPPORT if(m_p->bIsSSL) { static_cast<QSslSocket *>(m_p->pSocket)->setProtocol(QSsl::AnyProtocol); static_cast<QSslSocket *>(m_p->pSocket)->connectToHostEncrypted(m_connectionUrl.host(), m_p->uPort); } else { m_p->pSocket->connectToHost(m_connectionUrl.host(), m_p->uPort); } #else m_p->pSocket->connectToHost(m_connectionUrl.host(), m_p->uPort); #endif if(m_p->pConnectTimeoutTimer) { delete m_p->pConnectTimeoutTimer; m_p->pConnectTimeoutTimer = nullptr; } m_p->pConnectTimeoutTimer = new QTimer(); m_p->pConnectTimeoutTimer->setSingleShot(true); QObject::connect(m_p->pConnectTimeoutTimer, SIGNAL(timeout()), this, SLOT(slotConnectionTimedOut())); m_p->pConnectTimeoutTimer->start(m_uConnectionTimeout * 1000); return true; }
void FQTermLocalSocket::stateChanged(QProcess::ProcessState newState) { switch(newState) { case QProcess::NotRunning: break; case QProcess::Starting: emit hostFound(); // shell_process_->write("dir\n"); break; case QProcess::Running: break; } }
void BSocket::ensureSocket() { if(!d->qsock) { d->qsock = new QSocket; #if QT_VERSION >= 0x030200 d->qsock->setReadBufferSize(READBUFSIZE); #endif connect(d->qsock, SIGNAL(hostFound()), SLOT(qs_hostFound())); connect(d->qsock, SIGNAL(connected()), SLOT(qs_connected())); connect(d->qsock, SIGNAL(connectionClosed()), SLOT(qs_connectionClosed())); connect(d->qsock, SIGNAL(delayedCloseFinished()), SLOT(qs_delayedCloseFinished())); connect(d->qsock, SIGNAL(readyRead()), SLOT(qs_readyRead())); connect(d->qsock, SIGNAL(bytesWritten(int)), SLOT(qs_bytesWritten(int))); connect(d->qsock, SIGNAL(error(int)), SLOT(qs_error(int))); }
void ClientListener::newConnection() { m_socket = m_tcpServer->nextPendingConnection(); m_tcpServer->close(); connect(m_socket, SIGNAL(hostFound()), SLOT(socketHostFound())); connect(m_socket, SIGNAL(connected()), SLOT(socketConnected())); connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(socketError(QAbstractSocket::SocketError))); connect(m_socket, SIGNAL(readyRead()), SLOT(socketReadyRead())); connect(m_socket, SIGNAL(bytesWritten(qint64)), SLOT(socketBytesWritten(qint64))); connect(m_socket, SIGNAL(disconnected()), SLOT(socketDisconnected())); changeState(Handshaking); m_stream.setDevice(m_socket); }
NetworkControl::NetworkControl() { client = new Client(); QObject::connect(client, SIGNAL(connected()), this, SLOT(onConnected())); QObject::connect(client, SIGNAL(hostFound()), this, SLOT(onHostFound())); QObject::connect(client, SIGNAL(loggingIn()), this, SLOT(onLoggingIn())); QObject::connect(client, SIGNAL(successfullJoin()), this, SLOT(onConnectionAccepted())); QObject::connect(client, SIGNAL(disconnected()), this, SLOT(onDisconnected())); QObject::connect(client, SIGNAL(presentationReceived(QString, QList<QImage>)), this, SLOT(onPresentationReceived(QString, QList<QImage>))); server = new Server(); QObject::connect(server, SIGNAL(listening()), this, SLOT(onStarted())); QObject::connect(server, SIGNAL(connectionAccepted()), this, SLOT(onClientConnected())); QObject::connect(server, SIGNAL(clientVerified()), this, SLOT(onClientVerified())); QObject::connect(server, SIGNAL(clientLeft()), this, SLOT(onClientLeft())); QObject::connect(server, SIGNAL(closing()), this, SLOT(onClosed())); }
ShoutCastIODevice::ShoutCastIODevice(void) : m_redirects (0), m_scratchpad_pos (0), m_state (NOT_CONNECTED) { m_socket = new QTcpSocket; m_response = new ShoutCastResponse; connect(m_socket, SIGNAL(hostFound()), SLOT(socketHostFound())); connect(m_socket, SIGNAL(connected()), SLOT(socketConnected())); connect(m_socket, SIGNAL(disconnected()), SLOT(socketConnectionClosed())); connect(m_socket, SIGNAL(readyRead()), SLOT(socketReadyRead())); connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(socketError(QAbstractSocket::SocketError))); switchToState(NOT_CONNECTED); setOpenMode(ReadWrite); }
OpenNIC::OpenNIC(QWidget *parent) : inherited(parent) , mActionSettings(NULL) , mActionAbout(NULL) , mActionQuit(NULL) , mTrayIcon(NULL) , mTrayIconMenu(NULL) , ui(new Ui::OpenNICSettings) , mRefreshTimer(0) , mPacketState(0) , mPacketLength(0) , mTcpListenPort(0) , mInitialized(false) , mBalloonIcon(QSystemTrayIcon::Information) , mActiveState(false) , mScoreRulesTextChanged(false) { ui->setupUi(this); createActions(); createTrayIcon(); QObject::connect(this,SIGNAL(accepted()),this,SLOT(writeSettings())); mTcpSocket.close(); mBalloonStatus = tr("Initializing..."); mRefreshTimer = startTimer(DEFAULT_REFRESH); mLocalNet = new OpenNICNet(&mTcpSocket); QObject::connect(mLocalNet,SIGNAL(dataReady(OpenNICNet*)),this,SLOT(dataReady(OpenNICNet*))); QObject::connect(&mTcpSocket,SIGNAL(connected()),this,SLOT(tcpConnected())); QObject::connect(&mTcpSocket,SIGNAL(disconnected()),this,SLOT(tcpDisconnected())); QObject::connect(&mTcpSocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(tcpError(QAbstractSocket::SocketError))); QObject::connect(&mTcpSocket,SIGNAL(stateChanged(QAbstractSocket::SocketState)),this,SLOT(tcpStateChanged(QAbstractSocket::SocketState))); QObject::connect(&mTcpSocket,SIGNAL(hostFound()),this,SLOT(tcpHostFound())); QObject::connect(this,SIGNAL(accepted()),this,SLOT(update())); QObject::connect(ui->saveT1List,SIGNAL(clicked()),this,SLOT(updateT1List())); QObject::connect(ui->buttonBox,SIGNAL(clicked(QAbstractButton*)),this,SLOT(clicked(QAbstractButton*))); QObject::connect(ui->refreshNow,SIGNAL(clicked()),this,SLOT(updateDNS())); QObject::connect(ui->tabs,SIGNAL(currentChanged(int)),this,SLOT(tabChanged(int))); QObject::connect(ui->saveDomains,SIGNAL(clicked()),this,SLOT(updateDomains())); QObject::connect(ui->resolverPoolTable,SIGNAL(cellClicked(int,int)),this,SLOT(cellClicked(int,int))); QObject::connect(ui->resolverPoolTable,SIGNAL(cellDoubleClicked(int,int)),this,SLOT(cellDoubleClicked(int,int))); QObject::connect(ui->scoreRuleEditor,SIGNAL(textChanged()),this,SLOT(scoreRuleEditorTextChanged())); setDisabledState(); }
NetworkControl::NetworkControl(PresentationControl* p) { pc = p; QObject::connect(pc, SIGNAL(presentationChanged()), this, SLOT(onPresentationChanged())); QThread* networkThread = new QThread(); client = new Client(); QObject::connect(client, SIGNAL(currentPageReceived(qint64)), pc, SLOT(onCurrenPageChanged(qint64))); QObject::connect(client, SIGNAL(connected()), this, SLOT(onConnected())); QObject::connect(client, SIGNAL(hostFound()), this, SLOT(onHostFound())); QObject::connect(client, SIGNAL(loggingIn()), this, SLOT(onLoggingIn())); QObject::connect(client, SIGNAL(successfullJoin()), this, SLOT(onConnectionAccepted())); QObject::connect(client, SIGNAL(disconnected()), this, SLOT(onDisconnected())); QObject::connect(client, SIGNAL(presentationReceived(QString, QList<QImage>)), this, SLOT(onPresentationReceived(QString, QList<QImage>))); server = new Server(); server->setPresentation(p->getPresentation()); QObject::connect(server, SIGNAL(listening()), this, SLOT(onStarted())); QObject::connect(server, SIGNAL(connectionAccepted()), this, SLOT(onClientConnected())); QObject::connect(server, SIGNAL(clientVerified()), this, SLOT(onClientVerified())); QObject::connect(server, SIGNAL(clientLeft()), this, SLOT(onClientLeft())); QObject::connect(server, SIGNAL(closing()), this, SLOT(onClosed())); }
void QAsioTcpSocket::customEvent(QEvent *event) { if (event->type() == QAsioEvent::QAsioSocketEventType) { QAsioEvent * e = static_cast<QAsioEvent*>(event); switch (e->getConnectedType()) { case QAsioEvent::ReadReadly : if (isDisconDelData && state() != ConnectedState) break; emit readReadly(); break; case QAsioEvent::Connected : emit stateChange(ConnectedState); emit connected(); break; case QAsioEvent::HaveEorro : emit sentError(erroSite(),error()); emit stateChange(UnconnectedState); emit disconnected(); break; case QAsioEvent::DisConnect : emit stateChange(UnconnectedState); emit disconnected(); break; case QAsioEvent::HostFined : emit hostFound(); break; case QAsioEvent::HeartTimeOut: emit heartTimeOuted(e->getData().toInt()); break; default: break; } e->accept(); } else { QObject::customEvent(event); } }
Robot::Robot(double x, double y, double a, QObject *parent){ md_linearVelocity=md_angularVelocity=0; md_wheelTrack=1.0; for (int i=0; i<2; ++i) m_wheel[i] = Wheel(0,0.3); md_position = new double [3]; md_position[0]=x; md_position[1]=y; md_position[2]=a; m_cylinder = Cylinder(); m_arm = Arm(); battery = new Battery(); state=BASIC; socket = new QTcpSocket(this); socket->connectToHost(QString("192.168.0.1"), 2000); connect(socket, SIGNAL(connected()), this, SLOT(connected())); connect(socket, SIGNAL(hostFound()), this, SLOT(connected())); connect(socket, SIGNAL(disconnected()), this, SLOT(not_connected())); bl=new char[4]; }
void Q3Socket::tryConnecting() { #if defined(Q3SOCKET_DEBUG) qDebug( "Q3Socket (%s)::tryConnecting()", name() ); #endif // ### this ifdef isn't correct - addresses() also does /etc/hosts and // numeric-address-as-string handling. #ifndef QT_NO_DNS if ( d->dns4 ) { d->l4 = d->dns4->addresses(); if ( !d->l4.isEmpty() || !d->dns4->isWorking() ) { #if defined(Q3SOCKET_DEBUG) qDebug( "Q3Socket (%s)::tryConnecting: host %s, port %d: " "%d IPv4 addresses", name(), d->host.ascii(), d->port, d->l4.count() ); #endif delete d->dns4; d->dns4 = 0; } } if ( d->dns6 ) { d->l6 = d->dns6->addresses(); if ( !d->l6.isEmpty() || !d->dns6->isWorking() ) { #if defined(Q3SOCKET_DEBUG) qDebug( "Q3Socket (%s)::tryConnecting: host %s, port %d: " "%d IPv6 addresses", name(), d->host.ascii(), d->port, d->l6.count() ); #endif delete d->dns6; d->dns6 = 0; } } if ( d->state == HostLookup ) { if ( d->l4.isEmpty() && d->l6.isEmpty() && !d->dns4 && !d->dns6 ) { // no results and we're not still looking: give up d->state = Idle; emit error( ErrHostNotFound ); return; } if ( d->l4.isEmpty() && d->l6.isEmpty() ) { // no results (yet): try again later return; } // we've found something. press on with that. if we later find // more, fine. emit hostFound(); d->state = Connecting; } if ( d->state == Connecting ) { d->addresses += d->l4; d->addresses += d->l6; d->l4.clear(); d->l6.clear(); // try one address at a time, falling back to the next one if // there is a connection failure. (should also support a timeout, // or do multiple TCP-level connects at a time, with staggered // starts to avoid bandwidth waste and cause fewer // "connect-and-abort" errors. but that later.) bool stuck = true; while( stuck ) { stuck = false; if ( d->socket && d->socket->connect( d->addr, d->port ) == false ) { if ( d->socket->error() == Q3SocketDevice::NoError ) { if ( d->wsn ) d->wsn->setEnabled( true ); return; // not serious, try again later } #if defined(Q3SOCKET_DEBUG) qDebug( "Q3Socket (%s)::tryConnecting: " "Gave up on IP address %s", name(), d->socket->peerAddress().toString().ascii() ); #endif delete d->wsn; d->wsn = 0; delete d->rsn; d->rsn = 0; delete d->socket; d->socket = 0; if(d->addresses.isEmpty()) { emit error( ErrConnectionRefused ); return; } } // if the host has more addresses, try another some. if ( d->socket == 0 && !d->addresses.isEmpty() ) { d->addr = *d->addresses.begin(); d->addresses.remove( d->addresses.begin() ); d->setSocketDevice( this, 0 ); stuck = true; #if defined(Q3SOCKET_DEBUG) qDebug( "Q3Socket (%s)::tryConnecting: Trying IP address %s", name(), d->addr.toString().ascii() ); #endif } }; // The socket write notifier will fire when the connection succeeds if ( d->wsn ) d->wsn->setEnabled( true ); } #endif }
bool ssh::dossh() { #ifdef USE_QSSH { if(m_connection && m_connection->state() != QSsh::SshConnection::Unconnected) { helpers::log("ssh: already connecting...", LOG_INF, qApp, 0); return true; } m_connection = new QSsh::SshConnection(params, this); connect(m_connection, SIGNAL(connected()), SLOT(onQsshConnected())); connect(m_connection, SIGNAL(error(QSsh::SshError)), SLOT(onQsshConnectionError(QSsh::SshError))); helpers::log("ssh: connecting START...", LOG_INF, qApp, 0); m_connection->connectToHost(); return false; } #else helpers::log("ssh: START: " + QString::number(QSslSocket::supportsSsl()), QSslSocket::supportsSsl() ? LOG_INF : LOG_ERR, qApp, 0); //http://stackoverflow.com/questions/15213139/simple-qssl-client-server-cannot-start-handshake-on-non-plain-connection QSslSocket *socket = new QSslSocket(this); socket->ignoreSslErrors(); socket->setPeerVerifyMode(QSslSocket::VerifyNone); socket->setProtocol(QSsl::SslV3); connect(socket, SIGNAL(encrypted()), this, SLOT(ready())); connect(socket, SIGNAL(encryptedBytesWritten(qint64)), this, SLOT(encryptedBytesWritten(qint64))); connect(socket, SIGNAL(modeChanged(QSslSocket::SslMode)), this, SLOT(modeChanged(QSslSocket::SslMode))); connect(socket, SIGNAL(peerVerifyError(const QSslError &)), this, SLOT(peerVerifyError(const QSslError &))); connect(socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors(const QList<QSslError> &))); connect(socket, SIGNAL(connected()), this, SLOT(connected())); connect(socket, SIGNAL(disconnected()), this, SLOT(disconnected())); connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error(QAbstractSocket::SocketError))); connect(socket, SIGNAL(hostFound()), this, SLOT(hostFound())); connect(socket, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *)), this, SLOT(proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *))); connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(stateChanged(QAbstractSocket::SocketState))); connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead())); { { QFile file( "c:/Users/gherczeg/.ssh/id_boot2docker" ); if( ! file.open( QIODevice::ReadOnly ) ) { QMessageBox::question(0, "Erreur", "Impossible de charger id_boot2docker"); return; } QSslKey key(&file); file.close(); helpers::log("ssh:keyok: "+QString::number(!key.isNull()), !key.isNull() ? LOG_INF : LOG_ERR, qApp, 0); socket->setPrivateKey( key ); } foreach (const QSslCertificate &cert, QSslCertificate::fromPath("c:/Users/gherczeg/.boot2docker/certs/boot2docker-vm/*.pem", QSsl::Pem, QRegExp::Wildcard)) { helpers::log("ssh:certok1: "+QString::number(!cert.isNull()), !cert.isNull() ? LOG_INF : LOG_ERR, qApp, 0); socket->setLocalCertificate( cert ); socket->sslConfiguration().caCertificates().append(cert); socket->addCaCertificate( cert ); socket->addDefaultCaCertificate(cert); } } socket->connectToHostEncrypted("127.0.0.1", 2022); //socket->connectToHost("127.0.0.1", 2022); bool bok = socket->waitForEncrypted(100000); //bool bok = socket->waitForConnected(100000); if(!bok) { helpers::log("ssh:!waited:"+QString::number(bok),LOG_ERR, qApp, 0); return; } helpers::log("ssh:waited4ecnrypt/connect:"+QString::number(bok),LOG_INF, qApp, 0); socket->startClientEncryption(); bool wait4Read1 = socket->waitForReadyRead(100000); helpers::log("ssh:wait4Read1:"+QString::number(wait4Read1),wait4Read1 ? LOG_INF : LOG_ERR, qApp, 0); QString s = "docker: do!"; qint64 written = socket->write(s.toStdString().c_str()); helpers::log("ssh:written:"+QString::number(written),written > 0 ? LOG_INF : LOG_ERR, qApp, 0); bool flushed = socket->flush(); helpers::log("ssh:flush:"+QString::number(flushed),flushed ? LOG_INF : LOG_ERR, qApp, 0); bool wait4Write = socket->waitForBytesWritten(100000); helpers::log("ssh:wait4Write:"+QString::number(wait4Write),wait4Write ? LOG_INF : LOG_ERR, qApp, 0); bool wait4Read2 = socket->waitForReadyRead(100000); helpers::log("ssh:wait4Read2:"+QString::number(wait4Read2),wait4Read2 ? LOG_INF : LOG_ERR, qApp, 0); socket->disconnectFromHost(); #endif }
RoboControllerSDK::RoboControllerSDK(QString serverAddr/*=QString("127.0.0.1")*/, quint16 udpStatusPortSend/*=14550*/, quint16 udpStatusPortListen/*=14555*/, quint16 udpControlPort/*=14560*/, quint16 tcpPort/*=14500*/) : mTcpSocket(NULL), mUdpStatusSocket(NULL), mUdpControlSocket(NULL) { mStopped = true; mWatchDogTimeMsec = 1000; mMsgCounter = 0; // Ping Timer connect( &mPingTimer, SIGNAL(timeout()), this, SLOT(onPingTimerTimeout())); // >>>>> TCP Socket mTcpSocket = new QTcpSocket(this); mServerAddr = serverAddr; mTcpPort = tcpPort; connect(mTcpSocket, SIGNAL(readyRead()), this, SLOT(onTcpReadyRead())); connect(mTcpSocket, SIGNAL(hostFound()), this, SLOT(onTcpHostFound())); connect(mTcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onTcpError(QAbstractSocket::SocketError))); try { connectToTcpServer(); } catch( RcException &e ) { qDebug() << e.getExcMessage(); throw e; } // <<<<< TCP Socket // >>>>> UDP Sockets mUdpControlSocket = new QUdpSocket(this); mUdpStatusSocket = new QUdpSocket(this); mUdpControlPortSend = udpControlPort; mUdpStatusPortSend = udpStatusPortSend; mUdpStatusPortListen = udpStatusPortListen; /*connect( mUdpControlSocket, SIGNAL(readyRead()), this, SLOT(onUdpControlReadyRead()) ); // The control UDP Socket does not receive!*/ connect( mUdpStatusSocket, SIGNAL(readyRead()), this, SLOT(onUdpStatusReadyRead()) ); connect( mUdpControlSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onUdpControlError(QAbstractSocket::SocketError)) ); connect( mUdpStatusSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onUdpStatusError(QAbstractSocket::SocketError)) ); try { connectToUdpServers(); } catch( RcException &e ) { qDebug() << e.getExcMessage(); throw e; } // <<<<< UDP Sockets mMotorCtrlMode = mcPID; // RoboController is in PID mode by default // Start thread mStopped = false; start(); }
bool KviHttpRequest::doConnect() { m_p->uPort = m_connectionUrl.port(); if(m_p->uPort == 0) m_p->uPort = m_p->bIsSSL ? 443 : 80; if(m_p->pSocket) closeSocket(); #ifdef COMPILE_SSL_SUPPORT m_p->pSocket = m_p->bIsSSL ? new QSslSocket() : new QTcpSocket(); #else m_p->pSocket = new QTcpSocket(); #endif QObject::connect(m_p->pSocket,SIGNAL(connected()),this,SLOT(slotSocketConnected())); QObject::connect(m_p->pSocket,SIGNAL(disconnected()),this,SLOT(slotSocketDisconnected())); QObject::connect(m_p->pSocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(slotSocketError(QAbstractSocket::SocketError))); QObject::connect(m_p->pSocket,SIGNAL(readyRead()),this,SLOT(slotSocketReadDataReady())); QObject::connect(m_p->pSocket,SIGNAL(hostFound()),this,SLOT(slotSocketHostResolved())); emit resolvingHost(m_connectionUrl.host()); #ifdef COMPILE_SSL_SUPPORT if(m_p->bIsSSL) { static_cast<QSslSocket *>(m_p->pSocket)->setProtocol(QSsl::AnyProtocol); static_cast<QSslSocket *>(m_p->pSocket)->connectToHostEncrypted(m_connectionUrl.host(),m_p->uPort); } else { m_p->pSocket->connectToHost(m_connectionUrl.host(),m_p->uPort); } #else m_p->pSocket->connectToHost(m_connectionUrl.host(),m_p->uPort); #endif if(m_p->pConnectTimeoutTimer) { delete m_p->pConnectTimeoutTimer; m_p->pConnectTimeoutTimer = NULL; } m_p->pConnectTimeoutTimer = new QTimer(); m_p->pConnectTimeoutTimer->setSingleShot(true); QObject::connect(m_p->pConnectTimeoutTimer,SIGNAL(timeout()),this,SLOT(slotConnectionTimedOut())); m_p->pConnectTimeoutTimer->start(m_uConnectionTimeout * 1000); /* m_pThread = new KviHttpRequestThread( this, m_connectionUrl.host(), m_szIp, uPort, m_connectionUrl.path(), m_uContentOffset, (m_eProcessingType == HeadersOnly) ? KviHttpRequestThread::Head : (m_szPostData.isEmpty() ? KviHttpRequestThread::Get : KviHttpRequestThread::Post), m_szPostData, m_connectionUrl.protocol()=="https" ); */ return true; }
WelcomeDialog::WelcomeDialog() : QDialog(NULL, "WelcomeDialog", true) { setCaption(tr("Welcome To Quasar")); QLabel* image = new QLabel(this); image->setPixmap(login_image); QFrame* right = new QFrame(this); _localeBox = new QGroupBox(right); QGridLayout* localeGrid = new QGridLayout(_localeBox, 2, 2, _localeBox->frameWidth() * 2); localeGrid->addRowSpacing(0, _localeBox->fontMetrics().height()); localeGrid->setMargin(6); localeGrid->setSpacing(3); localeGrid->setColStretch(1, 1); _localeMsg = new QLabel(_localeBox); _localeLabel = new QLabel(_localeBox); _locale = new ComboBox(_localeBox); _localeLabel->setBuddy(_locale); _locale->setMaximumWidth(320); localeGrid->addMultiCellWidget(_localeMsg, 1, 1, 0, 1); localeGrid->addWidget(_localeLabel, 2, 0); localeGrid->addWidget(_locale, 2, 1, AlignLeft | AlignVCenter); _serverBox = new QGroupBox(right); QGridLayout* serverGrid = new QGridLayout(_serverBox, 2, 2, _serverBox->frameWidth() * 2); serverGrid->addRowSpacing(0, _serverBox->fontMetrics().height()); serverGrid->setMargin(6); serverGrid->setSpacing(3); serverGrid->setColStretch(1, 1); _serverMsg = new QLabel(_serverBox); _serverLabel = new QLabel(_serverBox); _server = new LineEdit(_serverBox); _serverLabel->setBuddy(_server); serverGrid->addMultiCellWidget(_serverMsg, 1, 1, 0, 1); serverGrid->addWidget(_serverLabel, 2, 0); serverGrid->addWidget(_server, 2, 1, AlignLeft | AlignVCenter); QGridLayout* rightGrid = new QGridLayout(right); rightGrid->setSpacing(3); rightGrid->setMargin(3); rightGrid->setRowStretch(1, 1); rightGrid->setRowStretch(3, 1); rightGrid->setColStretch(0, 1); rightGrid->addWidget(_localeBox, 0, 0); rightGrid->addWidget(_serverBox, 2, 0); QFrame* buttons = new QFrame(this); _status = new QLabel(buttons); _ok = new QPushButton(tr("OK"), buttons); _cancel = new QPushButton(tr("Cancel"), buttons); _ok->setDefault(true); _ok->setMinimumSize(_cancel->sizeHint()); _cancel->setMinimumSize(_cancel->sizeHint()); connect(_ok, SIGNAL(clicked()), SLOT(accept())); connect(_cancel, SIGNAL(clicked()), SLOT(reject())); QGridLayout* buttonGrid = new QGridLayout(buttons); buttonGrid->setSpacing(6); buttonGrid->setMargin(3); buttonGrid->setColStretch(0, 1); buttonGrid->addWidget(_status, 0, 0); buttonGrid->addWidget(_ok, 0, 1); buttonGrid->addWidget(_cancel, 0, 2); _locales = Locale::getAvailableLocales(_localesCnt); slotLocaleChanged(); QGridLayout* grid = new QGridLayout(this); grid->setSpacing(3); grid->setMargin(6); grid->setRowStretch(0, 1); grid->setColStretch(1, 1); grid->addWidget(image, 0, 0); grid->addWidget(right, 0, 1); grid->addMultiCellWidget(buttons, 1, 1, 0, 1); _quasar = new QuasarClient(this); _timer = new QTimer(this); connect(_locale, SIGNAL(activated(int)), SLOT(slotLocaleChanged())); connect(_quasar, SIGNAL(hostFound()), SLOT(slotHostFound())); connect(_quasar, SIGNAL(connected()), SLOT(slotConnected())); connect(_quasar, SIGNAL(connectionError(int)), SLOT(slotConnectionError(int))); connect(_timer, SIGNAL(timeout()), SLOT(slotTimeout())); _server->setText("localhost"); _locale->setFocus(); }