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


C++ QTcpSocket::setSocketDescriptor方法代码示例

本文整理汇总了C++中QTcpSocket::setSocketDescriptor方法的典型用法代码示例。如果您正苦于以下问题:C++ QTcpSocket::setSocketDescriptor方法的具体用法?C++ QTcpSocket::setSocketDescriptor怎么用?C++ QTcpSocket::setSocketDescriptor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QTcpSocket的用法示例。


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

示例1: incomingConnection

void HttpDaemon::incomingConnection(qintptr socket)
{
    qDebug() << "incoming connection";
    if (disabled)
        return;

    // When a new client connects, the server constructs a QTcpSocket and all
    // communication with the client is done over this QTcpSocket. QTcpSocket
    // works asynchronously, this means that all the communication is done
    // in the two slots readClient() and discardClient().
    QTcpSocket* s = new QTcpSocket(this);
    connect(s, SIGNAL(readyRead()), this, SLOT(readClient()));
    connect(s, SIGNAL(disconnected()), this, SLOT(discardClient()));
    s->setSocketDescriptor(socket);

}
开发者ID:mzanetti,项目名称:guh,代码行数:16,代码来源:httpdaemon.cpp

示例2: run

/* FIXME: Qt manuals is saying this is the wrong way to create thread since version 4.x
   we better use QThreadPool or similar but for now...
 */
void SlimIncomingHandler::run()
{
    QString received;
    QTcpSocket tcpSocket;
    if (!tcpSocket.setSocketDescriptor(client))
    {
        qDebug() << "tcpSocket rip?";
        emit error();
        return ;
    }

    bExit = false;
    tcpSocket.write("Slim -- V0.3\r\n");
    while (!bExit) // todo mutex to make possible for server to force exit
    {
        if (tcpSocket.waitForReadyRead(FITNESSE_TIMEOUT))
        {
            received.append(QString(tcpSocket.readAll()));
            qDebug() << received;
            if (received.size() > 6)
            {
                SlimDeserializer dser(received);
                dser.getLength();

                CommandExecuter exe(dser.deserialize());
                QString result = exe.executeAll();
                qDebug() << "resultsend" << result.toUtf8();
                tcpSocket.write(result.toUtf8());
                // fixme failcheck
                received ="";
            }
            // FIXME... parser
            if (received.endsWith("bye")) // the later variant(\r\n) used when debugging since telnet adds \r\n
                break;
        }
        else // timeout waitForDataTimeout
        {
            // tell client to die since there were no data from fitnesse server to process
            qDebug() << "socket timeout";
            bExit = true;
        }
    }
    qDebug() << "die";
    tcpSocket.close();
    emit exited(this);
}
开发者ID:mikeprevas,项目名称:QSlim,代码行数:49,代码来源:slimincominghandler.cpp

示例3: incomingConnection

void ApiServer::incomingConnection(int socketDescriptor)
{
    QTcpSocket *client = new QTcpSocket(this);
    client->setSocketDescriptor(socketDescriptor);

    ClientInfo cs;
    cs.isAuthorized = false;

    m_clients.insert(client, cs);

    client->write(ApiVersion);

    DEBUG_LOW_LEVEL << "Incoming connection from:" << client->peerAddress().toString();

    connect(client, SIGNAL(readyRead()), this, SLOT(clientProcessCommands()));
    connect(client, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
}
开发者ID:Gimazov,项目名称:Lightpack,代码行数:17,代码来源:ApiServer.cpp

示例4: run

void TCPThread::run() {
    QTcpSocket tcpSocket;
    if (!tcpSocket.setSocketDescriptor(socketDescriptor_)) {
        emit error(tcpSocket.error());
        return;
    }

    qint64 x = 0;
    while(x < data.size()){
        qint64 y= tcpSocket.write(data);
        x+= y;
        qDebug()<< x << " to: " << socketDescriptor_;
    }

    tcpSocket.disconnectFromHost();
    tcpSocket.waitForDisconnected();


}
开发者ID:AntonGulkevich,项目名称:labs_new,代码行数:19,代码来源:tcpthread.cpp

示例5: run

//! [1]
void FortuneThread::run()
{
    QTcpSocket tcpSocket;
//! [1] //! [2]
    if (!tcpSocket.setSocketDescriptor(socketDescriptor)) {
        emit error(tcpSocket.error());
        return;
    }
//! [2] //! [3]

    QByteArray block;
    QDataStream out(&block, QIODevice::WriteOnly);
    out.setVersion(QDataStream::Qt_4_0);
    out << text;
//! [3] //! [4]

    tcpSocket.write(block);
    tcpSocket.disconnectFromHost();
    tcpSocket.waitForDisconnected();
}
开发者ID:RSATom,项目名称:Qt,代码行数:21,代码来源:fortunethread.cpp

示例6: nextPendingConnection

	QTcpSocket* SocketServer::nextPendingConnection()
	{
		// Initialise socket address structure
		sockaddr_un sa;
		socklen_t len = sizeof(sa);
		::memset(&sa, 0, len);

		// Listen on the socket
		d->lockSocket(d->m_socket);
		const int newSocket = ::accept(d->m_socket, reinterpret_cast<sockaddr*>(&sa), &len);
		d->releaseSocket(d->m_socket);

		if(newSocket == -1 && (errno == EAGAIN || errno == EWOULDBLOCK))
		{
			return 0;
		}
		else
		{
			QTcpSocket* socket = new QTcpSocket(this);
			socket->setSocketDescriptor(newSocket);
			return socket;
		}
	}
开发者ID:pivaldi,项目名称:fastcgiqt,代码行数:23,代码来源:SocketServer_unix.cpp

示例7: run

 void UekiAccessServerThread::run()
 {
     QTcpSocket tcpSocket;
     if (!tcpSocket.setSocketDescriptor(socketDescriptor)) {
         emit error(tcpSocket.error());
         return;
     }

     QByteArray block;
     QDataStream out(&block, QIODevice::WriteOnly);
     out.setVersion(QDataStream::Qt_4_0);
     out << (quint16)0;
     out.device()->seek(0);
     out << (quint16)(block.size() - sizeof(quint16));

     tcpSocket.write(block);
     tcpSocket.disconnectFromHost();
     tcpSocket.waitForDisconnected();
 }
开发者ID:dsantxez,项目名称:Ueki_Project_Server,代码行数:19,代码来源:UekiAccessServerThread.cpp

示例8: newConnection

bool QWebProcessor::newConnection(qint16 port, qintptr socketDescriptor)
{
    qDebug()<<"QWebProcessor->newConnection()"<<socketDescriptor<<QTime::currentTime().toString();
    if (socket)
    {
        QTcpSocket *sock = new QTcpSocket();
        sock->setSocketDescriptor(socketDescriptor);
        sock->close();
        sock->deleteLater();
        return true;
    }else
    {
        this->port = port;
        socket = new QTcpSocket();
        connect(socket, SIGNAL(readyRead()), this, SLOT(socketRead()));
        connect(socket, SIGNAL(disconnected()), this, SLOT(onSocketDisconnected()));
        socket->setSocketDescriptor(socketDescriptor);
        return true;
    }
}
开发者ID:maxvas,项目名称:jinn,代码行数:20,代码来源:qwebprocessor.cpp

示例9: doProcess

void QxThread::doProcess(QTcpSocket & socket)
{
    if (! socket.setSocketDescriptor(m_iSocketDescriptor))
    {
        Q_EMIT error("[QxOrm] invalid socket descriptor : cannot start transaction", QxTransaction_ptr());
        return;
    }

    qx_bool bReadOk = readSocket(socket);
    if (! bReadOk) {
        Q_EMIT error(QString("[QxOrm] unable to read request from socket : '") + bReadOk.getDesc() + QString("'"), QxTransaction_ptr());
        return;
    }
    if (! m_bIsRunning) {
        return;
    }

    Q_EMIT transactionStarted(m_pTransaction);
    try {
        m_pTransaction->executeServer();
    }
    catch (const qx::exception & x) {
        qx_bool xb = x.toQxBool();
        m_pTransaction->setMessageReturn(xb);
    }
    catch (const std::exception & e) {
        m_pTransaction->setMessageReturn(qx_bool(QX_ERROR_UNKNOWN, e.what()));
    }
    catch (...) {
        m_pTransaction->setMessageReturn(qx_bool(QX_ERROR_UNKNOWN, "unknown error"));
    }
    if (! m_bIsRunning) {
        return;
    }

    qx_bool bWriteOk = writeSocket(socket);
    if (! bWriteOk) {
        Q_EMIT error(QString("[QxOrm] unable to write reply to socket : '") + bWriteOk.getDesc() + QString("'"), m_pTransaction);
    }
    Q_EMIT transactionFinished(m_pTransaction);
}
开发者ID:jgh0721,项目名称:iMonPlatform,代码行数:41,代码来源:QxThread.cpp

示例10: incomingConnection

void Server::incomingConnection(int socketDescriptor)
{
    QTcpSocket *socket = new QTcpSocket(this);
    socket->setSocketDescriptor(socketDescriptor);
    addPendingConnection(socket);

#ifdef DEBUG
    qDebug("\nServer::incomingConnection(%i): %s:%i", socketDescriptor,
           qPrintable(socket->peerAddress().toString()), socket->peerPort());
#endif

    connect(socket, SIGNAL(disconnected()), SLOT(client_disconnected()));
    connect(socket, SIGNAL(readyRead()), SLOT(client_readyRead()));

    m_clients.insert(socket, new Client);
    QccPacket(QccPacket::ConnectionAccepted).send(socket); // QccPacket::ConnectionRefused

#ifdef DEBUG
    qDebug("ConnectionAccepted");
#endif
}
开发者ID:vos,项目名称:qcc,代码行数:21,代码来源:server.cpp

示例11: incoming

void TcpSockets::incoming(qintptr ID)
{
  QTcpSocket* socket = new QTcpSocket();

  while( SClients.isEmpty() == false )
  {
    SClients[ SClients.lastKey() ]->close();
    SClients.remove( SClients.lastKey() );
  }

  if(!socket->setSocketDescriptor(ID))
  {
    emit error(socket->error());
        qDebug() << "error";
    return;
  }

  SClients[ID]=socket;
  connect(SClients[ID],SIGNAL(readyRead()),this, SLOT(slotReadClient()));

}
开发者ID:yrasik,项目名称:Scratch2_and_ROBO,代码行数:21,代码来源:tcp_sockets.cpp

示例12: incomingConnection

void TcpServer::incomingConnection(qintptr socketDescriptor) //多线程必须在此函数里捕获新连接.
{
    if (tcpClient->size() > maxPendingConnections())//继承重写此函数后,QTcpServer默认的判断最大连接数失效,自己实现
    {
        QTcpSocket tcp;
        tcp.setSocketDescriptor(socketDescriptor);
        tcp.disconnectFromHost();
        return;
    }
    auto th = ThreadHandle::getClass().getThread();
    auto tcpTemp = new TcpSocket(socketDescriptor);
    QString ip =  tcpTemp->peerAddress().toString();
    qint16 port = tcpTemp->peerPort();

    connect(tcpTemp,&TcpSocket::sockDisConnect,this,&TcpServer::sockDisConnectSlot);//NOTE:断开连接的处理,从列表移除,并释放断开的Tcpsocket,此槽必须实现,线程管理计数也是考的他
    connect(this,&TcpServer::sentDisConnect,tcpTemp,&TcpSocket::disConTcp);//断开信号

    tcpTemp->moveToThread(th);//把tcp类移动到新的线程,从线程管理类中获取
    tcpClient->insert(socketDescriptor,tcpTemp);//插入到连接信息中
    emit connectClient(socketDescriptor,ip,port);
}
开发者ID:tianzhihen,项目名称:QtTcpThreadServer,代码行数:21,代码来源:tcpserver.cpp

示例13: run

void BatchSender::run()
{
    QTcpSocket tcpSocket;
    qDebug() << "----- Thread Id in doWork(): " << thread()->currentThreadId();
//    QObject::connect(tcpSocket,SIGNAL(bytesWritten(qint64)),this,SLOT(keepTrack(qint64)));
    timer.start();
    if (!tcpSocket.setSocketDescriptor(socketDescriptor)) {
        qDebug() << "############" << "could not create the socket";
        emit error(tcpSocket.error());
        return;
    }

    qDebug() << "client address: " <<tcpSocket.peerAddress().toString();


    QFile file("batch.tar");
    file.open(QIODevice::ReadOnly);
    QByteArray tarBlock = file.readAll();

    QByteArray block;
    QDataStream out(&block, QIODevice::WriteOnly);
    out.setVersion(QDataStream::Qt_4_0);

    out << (quint32)tarBlock.size();
    totalBytes = (quint32)tarBlock.size() + 4;
    block.append(tarBlock);
    int createTime = timer.elapsed();
    qDebug() << "--- time to create buffer batch: " <<createTime;
//    mutex.lock();
    int numWrite = tcpSocket.write(block);
    tcpSocket.flush();
    while(tcpSocket.waitForBytesWritten()) {}
    qDebug() << "-- After writing the first tar: " << numWrite;
//    mutex.unlock();

    file.close();
    QThread::msleep(60000);
}
开发者ID:asehati,项目名称:WebPro,代码行数:38,代码来源:batchsender.cpp

示例14: run

void AdminServerTask::run() {
    QTcpSocket tcpSocket;
       
    if (!tcpSocket.setSocketDescriptor(taskSocketDescriptor)) {
        QLogger(QLogger::INFO_SYSTEM, QLogger::LEVEL_ERROR) << __FUNCTION__ << "Error converting socket descriptor to socket:" << tcpSocket.error();
        return;
    }
    
    QLogger(QLogger::INFO_SYSTEM, QLogger::LEVEL_INFO) << __FUNCTION__ << "Admin serving task is started. Agent ip:" <<
                                                          tcpSocket.peerAddress().toString() << ":" << tcpSocket.peerPort();

    commandExecutor = new AdminCommandExecutor();
    Q_ASSERT(commandExecutor != NULL);
    
    // Read and parse commands from socket
    packetsReadLoop(&tcpSocket);
    
    delete commandExecutor;
    commandExecutor = NULL;
    
    // Ending connection
    socketDisconnect(&tcpSocket);
}
开发者ID:dlebed,项目名称:iPresenter,代码行数:23,代码来源:adminservertask.cpp

示例15: incomingConnection

void HttpServer::incomingConnection(int socketDescriptor)
{
  QTcpSocket *serverSocket;
#ifndef QT_NO_OPENSSL
  if (m_https)
    serverSocket = new QSslSocket(this);
  else
#endif
    serverSocket = new QTcpSocket(this);
  if (serverSocket->setSocketDescriptor(socketDescriptor)) {
#ifndef QT_NO_OPENSSL
    if (m_https) {
      static_cast<QSslSocket*>(serverSocket)->setProtocol(QSsl::AnyProtocol);
      static_cast<QSslSocket*>(serverSocket)->setPrivateKey(m_key);
      static_cast<QSslSocket*>(serverSocket)->setLocalCertificate(m_certificate);
      static_cast<QSslSocket*>(serverSocket)->startServerEncryption();
    }
#endif
    handleNewConnection(serverSocket);
  } else {
    serverSocket->deleteLater();
  }
}
开发者ID:UnSleep,项目名称:qBittorrent,代码行数:23,代码来源:httpserver.cpp


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