当前位置: 首页>>代码示例>>C++>>正文


C++ connectToHost函数代码示例

本文整理汇总了C++中connectToHost函数的典型用法代码示例。如果您正苦于以下问题:C++ connectToHost函数的具体用法?C++ connectToHost怎么用?C++ connectToHost使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了connectToHost函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: commandStarted

Network::Network(const QString &host, quint16 port) : commandStarted(false)
{
    if (port == 0) {
        //Default argument, not worth going further
    } else {
        connectToHost(host, port);
    }

    connect(this, SIGNAL(readyRead()), SLOT(onReceipt()));
}
开发者ID:Airisu,项目名称:pokemon-online,代码行数:10,代码来源:network.cpp

示例2: connectToHost

void OftSocket::directConnect(const QHostAddress &addr, quint16 port)
{
	m_state = ReadHeader;
	connectToHost(addr, port);
	m_clientPort = port;
	m_timer.start();
	debug().nospace() << "Trying to establish a direct connection to "
			<< addr.toString().toLocal8Bit().constData()
			<< ":" << port;
}
开发者ID:AlexeyProkhin,项目名称:ireen,代码行数:10,代码来源:oscarfiletransfer.cpp

示例3: connectToHost

void ZMClient::restartConnection()
{
    // Reset the flag
    m_zmclientReady = false;
    m_bConnected = false;
    m_server_unavailable = false;

    // Retry to connect. . .  Maybe the user restarted mythzmserver?
    connectToHost(m_hostname, m_port);
}
开发者ID:ReArtu,项目名称:mythtv,代码行数:10,代码来源:zmclient.cpp

示例4: QMainWindow

MainWindow::MainWindow(QWidget *parent) :
	QMainWindow(parent),
	ui(new Ui::MainWindow)
{
	ui->setupUi(this);
	ui->gameBox->setEnabled(FALSE);
	connect(ui->clientButton, SIGNAL(released()), this, SLOT(connectToHost()));
	connect(ui->serverButton, SIGNAL(released()), this, SLOT(runServer()));
	moves = 0;
}
开发者ID:safiyat,项目名称:TicTacToe,代码行数:10,代码来源:MainWindow.cpp

示例5: connectToHost

void ApcUpsMon::requestEvents()
{
    if (socket.state() == QAbstractSocket::ConnectedState) {
        socket.putChar('\0');
        socket.putChar('\x06');
        socket.write("events");
    } else {
        // We're not connected, try and reconnect?
        connectToHost();
    }
}
开发者ID:licehunter,项目名称:plasma-apcups,代码行数:11,代码来源:apcupsc.cpp

示例6: Q_ASSERT

void Connection::connectToServer() {
    Q_ASSERT(!m_host.isEmpty());
    Q_ASSERT(m_port);

    connect(this, SIGNAL(connected()), SLOT(onConnected()), Qt::UniqueConnection);
    connect(this, SIGNAL(disconnected()), SLOT(onDisconnected()), Qt::UniqueConnection);
    connect(this, SIGNAL(readyRead()), SLOT(onReadyRead()), Qt::UniqueConnection);
    connect(this, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(onError(QAbstractSocket::SocketError)), Qt::UniqueConnection);

    connectToHost(m_host, m_port);
}
开发者ID:Anvar69,项目名称:libqtelegram-aseman-edition,代码行数:11,代码来源:connection.cpp

示例7: while

void *connect(void *data){
    struct program_data *tData;
    tData = (struct program_data*) data;
    while ((*tData).hasQuit == 0){
        connectToHost((*tData).ipInput);
        sleep(10);//prevents spamming the network if server is down
    }
    
    return NULL;
    
}
开发者ID:dewso,项目名称:ReStat,代码行数:11,代码来源:main.cpp

示例8: QObject

Server::Server(QObject * parent) : QObject(parent)
{
	_server = new QTcpServer(this);
	connect(_server, SIGNAL(newConnection()), SLOT(connected()));
	if(connectToHost(QHostAddress::Any, 8081)) {
        // Pokud jsme tady, server jeste neni pripojen k Log!!!
        syslog(LOG_INFO, "Server is listening...");
    } else {
        syslog(LOG_ERR, "Could not listen on given port!");
	}
}
开发者ID:puzzleSEQ,项目名称:server,代码行数:11,代码来源:server.cpp

示例9: Q_D

/*!
    If there's a connection activity on the socket, process it. Then
    notify our parent if there really was activity.
*/
void QNativeSocketEngine::connectionNotification()
{
    Q_D(QNativeSocketEngine);
    Q_ASSERT(state() == QAbstractSocket::ConnectingState);

    connectToHost(d->peerAddress, d->peerPort);
    if (state() != QAbstractSocket::ConnectingState) {
        // we changed states
        QAbstractSocketEngine::connectionNotification();
    }
}
开发者ID:Blizzard,项目名称:qt4,代码行数:15,代码来源:qnativesocketengine.cpp

示例10: QMainWindow

MainWindow::MainWindow(Socket *connection, QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    connection(connection)
{
    ui->setupUi(this);

    /* Disable unavailable offline control
     */
    ui->configurationWidget->setDisabled(true);
    ui->controlWidget->setDisabled(true);
    ui->PiecesDock->setDisabled(true);
    ui->stopButton->setDisabled(true);
    ui->resumeButton->setDisabled(true);

    /* Connection/Disconnection notification
     */
    connect(connection, SIGNAL(connected()), this, SLOT(connectionNotify()));
    connect(connection, SIGNAL(disconnected()), this, SLOT(disconnectionNotify()));

    /* Received logLine
     */
    connect(connection, SIGNAL(gotLog(QString)), this, SLOT(appendLog(QString)));

    /* Received Boxed info
     */
    connect(connection, SIGNAL(gotAccepted(int)), this, SLOT(addAccepted(int)));
    connect(connection, SIGNAL(gotRejected(int)), this, SLOT(addRejected(int)));

    /* Received Error / Warning
     */
    connect(connection, SIGNAL(gotError(int)), this, SLOT(errorNotify(int)));
    //connect(connection, SIGNAL(gotWarning(int)), this, SLOT(warningNotify(int)));

    /* Connection button
     */
    connect(ui->ConnectionButton, SIGNAL(clicked()), this, SLOT(connectToHost()));

    /* Send configuration data button
     */
    connect(ui->sendConfigButton, SIGNAL(clicked()), this, SLOT(sendConfig()));

    /* Actions button : Lauch / Resume / Stop
     */
    connect(ui->launchButton, SIGNAL(clicked()), this, SLOT(launch()));
    connect(ui->resumeButton, SIGNAL(clicked()), this, SLOT(resume()));
    connect(ui->stopButton, SIGNAL(clicked()), this, SLOT(stop()));

    /* Refresh time display
     */
    connect(&timer, SIGNAL(timeout()), this, SLOT(displayTime()));

    timer.start(50);
}
开发者ID:modSquad,项目名称:cmmai,代码行数:54,代码来源:mainwindow.cpp

示例11: SLOT

// Have a socket error, set m_errorString and propagate
// signal
void ApcUpsMon::socketError(QAbstractSocket::SocketError)
{
    m_errorString = socket.errorString();
    if (socket.state() != QAbstractSocket::ConnectedState) {
        // Attempt to reconnect in two timer intervals or,
        // failing that, ten seconds
        QTimer::singleShot((timer.interval() ? timer.interval() : 10000),
                           this, SLOT(connectToHost()));
    }
    
    emit haveError(m_errorString);
}
开发者ID:licehunter,项目名称:plasma-apcups,代码行数:14,代码来源:apcupsc.cpp

示例12: waitForWrite

/*!
    Waits for \a msecs milliseconds or until the socket is ready for
    writing. If \a timedOut is not 0 and \a msecs milliseconds have
    passed, the value of \a timedOut is set to true.

    Returns true if data is available for writing; otherwise returns
    false.

    This is a blocking function call; its use is disadvised in a
    single threaded application, as the whole thread will stop
    responding until the function returns. waitForWrite() is most
    useful when there is no event loop available. The general approach
    is to create a QSocketNotifier, passing the socket descriptor
    returned by socketDescriptor() to its constructor.
*/
bool QNativeSocketEngine::waitForWrite(int msecs, bool *timedOut)
{
    Q_D(QNativeSocketEngine);
    Q_CHECK_VALID_SOCKETLAYER(QNativeSocketEngine::waitForWrite(), false);
    Q_CHECK_NOT_STATE(QNativeSocketEngine::waitForWrite(),
                      QAbstractSocket::UnconnectedState, false);

    if (timedOut)
        *timedOut = false;

    int ret = d->nativeSelect(msecs, false);
    // On Windows, the socket is in connected state if a call to
    // select(writable) is successful. In this case we should not
    // issue a second call to WSAConnect()
#if defined (Q_WS_WIN)
    if (ret > 0) {
        setState(QAbstractSocket::ConnectedState);
        d_func()->fetchConnectionParameters();
        return true;
    } else {
        int value = 0;
        int valueSize = sizeof(value);
        if (::getsockopt(d->socketDescriptor, SOL_SOCKET, SO_ERROR, (char *) &value, &valueSize) == 0) {
            if (value == WSAECONNREFUSED) {
                d->setError(QAbstractSocket::ConnectionRefusedError, QNativeSocketEnginePrivate::ConnectionRefusedErrorString);
                d->socketState = QAbstractSocket::UnconnectedState;
                return false;
            } else if (value == WSAETIMEDOUT) {
                d->setError(QAbstractSocket::NetworkError, QNativeSocketEnginePrivate::ConnectionTimeOutErrorString);
                d->socketState = QAbstractSocket::UnconnectedState;
                return false;
            } else if (value == WSAEHOSTUNREACH) {
                d->setError(QAbstractSocket::NetworkError, QNativeSocketEnginePrivate::HostUnreachableErrorString);
                d->socketState = QAbstractSocket::UnconnectedState;
                return false;
            }
        }
    }
#endif

    if (ret == 0) {
        if (timedOut)
            *timedOut = true;
        d->setError(QAbstractSocket::SocketTimeoutError,
                    QNativeSocketEnginePrivate::TimeOutErrorString);
        d->hasSetSocketError = false; // A timeout error is temporary in waitFor functions
        return false;
    } else if (state() == QAbstractSocket::ConnectingState) {
        connectToHost(d->peerAddress, d->peerPort);
    }

    return ret > 0;
}
开发者ID:Blizzard,项目名称:qt4,代码行数:68,代码来源:qnativesocketengine.cpp

示例13: login

bool KMSmtpClient::login()
{
    //Check out state.
    if((!isConnected()) && (!connectToHost()))
    {
        //Means socket is still not connected to server or already login.
        return false;
    }
    //Check auth method.
    if(authMethod()==AuthPlain)
    {
        //Sending command: AUTH PLAIN base64('\0' + username + '\0' + password)
        sendMessage("AUTH PLAIN " + QByteArray().append((char)0x00)
                    .append(userName()).append((char)0x00)
                    .append(password()).toBase64());
        // The response code needs to be 235.
        if(!waitAndCheckResponse(235, ServerError))
        {
            //Failed to login.
            return false;
        }
        //Mission complete.
        return true;
    }
    //Then the method should be auth login.
    // Sending command: AUTH LOGIN
    sendMessage("AUTH LOGIN");
    //The response code needs to be 334.
    if(!waitAndCheckResponse(334, AuthenticationFailedError))
    {
        //Failed to login.
        return false;
    }
    // Send the username in base64
    sendMessage(QByteArray().append(userName()).toBase64());
    //The response code needs to be 334.
    if(!waitAndCheckResponse(334, AuthenticationFailedError))
    {
        //Failed to login.
        return false;
    }
    // Send the password in base64
    sendMessage(QByteArray().append(password()).toBase64());
    //If the response is not 235 then the authentication was faild
    if(!waitAndCheckResponse(235, AuthenticationFailedError))
    {
        //Failed to login.
        return false;
    }
    //Mission compelte.
    return true;
}
开发者ID:Kreogist,项目名称:Mail,代码行数:52,代码来源:kmsmtpclient.cpp

示例14: enviarRespuesta

void enviarRespuesta(char* hostname,char* respuesta) {
	char request[1000];
        setupSocket(hostname);
        connectToHost(hostname);
        sprintf(request,"GET /index.php?r=juego/respuesta&tokenSolicitud=%s&solucion=%s HTTP/1.1\r\nHost: %s\r\n\r\n",tokenSolicitud,respuesta,hostname);
        //http://hornero.fi.uncoma.edu.ar/index.php?r=juego/respuesta&&tokenSolicitud=76d7cadd3df99e06ae8c4aa580ca6900&solucion=-5933
	printf("\nse envia request: %s\n", request);
	if (send(sock, request, sizeof(request), 0) != (int)sizeof(request)) {
		printf( "Error sending request." );
		exit(1);
	}
        getBuffer();
}
开发者ID:cnngimenez,项目名称:hornero,代码行数:13,代码来源:hornero.c

示例15: setServerPort

void TcpClient::tryConnectToHost(const QString &host, int port)
{
    setServerPort(port);
    if (host == zeroHost) {
        if (!findLocalIpv4InterfaceData()) {
            return;
        }
    } else {
        if (connectToHost(host, port)) {
            setServerIp(host);
        }
    }
}
开发者ID:TatianaBorisova,项目名称:TestApplication,代码行数:13,代码来源:tcpclient.cpp


注:本文中的connectToHost函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。