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


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

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


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

示例1: run

void lsLogServitemThreated::run()
{
    QTcpSocket tcpSocket;

    if (!tcpSocket.setSocketDescriptor(socketDescriptor)) {
        emit error(tcpSocket.error());
        return;
    }

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

        tcpSocket.write(block);
        tcpSocket.flush();

        while ( tcpSocket.isOpen() && text.isEmpty() )
        {
            msleep(100);
        }
    }

    tcpSocket.disconnectFromHost();
    tcpSocket.waitForDisconnected();
}
开发者ID:audioprog,项目名称:UsbCopyManager,代码行数:32,代码来源:lsLogServitemThreated.cpp

示例2: newConnection

void CommunicationTcpSocketServer::newConnection()
{
    QTcpSocket *newSocket = serverSocket.nextPendingConnection();
    if (newSocket)
    {
        if (newSocket->isOpen()) {
            connect(newSocket, SIGNAL(disconnected()), this, SLOT(disconnected()));
        }
        setSocket(newSocket);
        qWarning() << "Új kapcsolat létesült.\n";


        QByteArray ba;
        ba[0]=0x00;
        ba[1]=0x55;
        ba[2]=100;
        ba[3]=122;
        send(ba);

        ba[0]=0x00;
        ba[1]=0xAA;
        ba[2]=128;
        ba[3]=14;
        send(ba);

        ba[0]=0x00;
        ba[1]=0xCB;
        ba[2]=15;
        ba[3]=192;
        send(ba);

    }
}
开发者ID:koincidencia,项目名称:MotorControllerSimulator,代码行数:33,代码来源:CommunicationTcpSocketServer.cpp

示例3: frameStart

void TCPReceiveRawNode::frameStart( qint64 pTimeStamp )
{
	if( !mStream )
	{
		return;
	}

	QTcpSocket		*S = qobject_cast<QTcpSocket *>( mStream->device() );

	if( !S->isOpen() )
	{
		delete mStream;
		delete S;

		mStream = nullptr;

		return;
	}

	if( !S->bytesAvailable() )
	{
		return;
	}

	fugio::Performance	Perf( mNode, "frameStart", pTimeStamp );

	mValOutputBuffer->setVariant( S->readAll() );

	pinUpdated( mPinOutputBuffer );
}
开发者ID:Daandelange,项目名称:Fugio,代码行数:30,代码来源:tcpreceiverawnode.cpp

示例4: sendMessage

void QtNetworkPeerPrivate::sendMessage(const QByteArray &message)
{
    qDebug() << "sendMessage" << message;

    foreach (const QHostAddress &address, m_acceptedOutboundConnections.keys()) {
        qDebug() << "sendMessage" << address;
        QTcpSocket *socket = m_acceptedOutboundConnections.value(address);
        qDebug() << "socket" << socket->isValid() << socket->isOpen();
        socket->write(message);
        socket->flush();
    }
}
开发者ID:msorvig,项目名称:qtnetworkpeer,代码行数:12,代码来源:qtnetworkpeer_p.cpp

示例5: main

int main(int argc, char** argv)
{
    QCoreApplication app(argc, argv);

    const QStringList args = app.arguments();
    QString arg_port;
    QString arg_server;
    QString arg_xmlFile;
    bool arg_crash = false;
    bool arg_garbage = false;
    uint arg_wait = 0;

    const QProcessEnvironment sysEnv = QProcessEnvironment::systemEnvironment();
    arg_xmlFile = sysEnv.value("QCIT_INPUT_FILE");

    for (int i = 1; i < args.size(); ++i) {
        const QString& arg = args.at(i);
        if (arg.startsWith(QLatin1String("--xml-socket="))) {
            arg_server = arg.mid(13, arg.indexOf(':') - 13);
            arg_port = arg.mid(13 + arg_server.length() + 1);
        } else if (args.size() > i + 1
                    && (args.at(i) == QLatin1String("-i")
                        || args.at(i) == QLatin1String("--xml-input"))) {
            arg_xmlFile = args.at(i+1);
            ++i;
        } else if (arg == QLatin1String("-c") || arg == QLatin1String("--crash")) {
            arg_crash = true;
        } else if (arg == QLatin1String("-g") || arg == QLatin1String("--garbage")) {
            arg_garbage = true;
        } else if (args.size() > i + 1 && (arg == QLatin1String("-w") || arg == QLatin1String("--wait"))) {
            bool ok;
            arg_wait = args.at(i+1).toUInt(&ok);
            if (!ok) {
                qerr << "ERROR: invalid wait time given" << args.at(i+1) << endl;
                usage(qerr);
                return 4;
            }
        } else if (args.at(i) == QLatin1String("--help") || args.at(i) == QLatin1String("-h")) {
            usage(qout);
            return 0;
        }
    }

    if (arg_xmlFile.isEmpty()) {
        qerr << "ERROR: no XML input file given" << endl;
        usage(qerr);
        return 1;
    }
    if (arg_server.isEmpty()) {
        qerr << "ERROR: no server given" << endl;
        usage(qerr);
        return 2;
    }
    if (arg_port.isEmpty()) {
        qerr << "ERROR: no port given" << endl;
        usage(qerr);
        return 3;
    }

    QFile xmlFile(arg_xmlFile);
    if (!xmlFile.exists() || !xmlFile.open(QIODevice::ReadOnly)) {
        qerr << "ERROR: invalid XML file" << endl;
        usage(qerr);
        return 10;
    }
    bool ok = false;
    quint16 port = arg_port.toUInt(&ok);
    if (!ok) {
        qerr << "ERROR: invalid port" << endl;
        usage(qerr);
        return 30;
    }

    QTcpSocket socket;
    socket.connectToHost(arg_server, port, QIODevice::WriteOnly);
    if (!socket.isOpen()) {
        qerr << "ERROR: could not open socket to server:" << arg_server << ":" << port << endl;
        usage(qerr);
        return 20;
    }
    if (!socket.waitForConnected()) {
        qerr << "ERROR: could not connect to socket: " << socket.errorString() << endl;
        return 21;
    }

    OutputGenerator generator(&socket, &xmlFile);
    QObject::connect(&generator, SIGNAL(finished()), &app, SLOT(quit()));
    generator.setCrashRandomly(arg_crash);
    generator.setOutputGarbage(arg_garbage);
    generator.setWait(arg_wait);

    return app.exec();
}
开发者ID:CNOT,项目名称:julia-studio,代码行数:93,代码来源:main.cpp

示例6: readClient


//.........这里部分代码省略.........
        }


        break;
      case "HEAD"_hash:
        break;
      case "POST"_hash:
        break;

// HTTP 1.1
      case "OPTIONS"_hash:
        break;
      case "PUT"_hash:
        break;
      case "DELETE"_hash:
        break;
      case "TRACE"_hash:
        break;
      case "CONNECT"_hash:
        break;
      case "PATCH"_hash:
        break;

  // HTTP 2.x (?)
      case "MOVE"_hash:
        break;
      case "PURGE"_hash:
        break;
      case "REFRESH"_hash:
        break;

  // WebDAV
  // HTTP 1.1
      case "PROPFIND"_hash:
        break;
      case "PROPPATCH"_hash:
        break;
      case "MKCOL"_hash:
        break;
      case "COPY"_hash:
        break;
      case "LOCK"_hash:
        break;
      case "UNLOCK"_hash:
        break;

  // HTTP 2.x
      case "VERSION-CONTROL"_hash:
        break;
      case "REPORT"_hash:
        break;
      case "CHECKIN"_hash:
        break;
      case "CHECKOUT"_hash:
        break;
      case "UNCHECKOUT"_hash:
        break;
      case "UPDATE"_hash:
        break;
      case "MKWORKSPACE"_hash:
        break;
      case "LABEL"_hash:
        break;
      case "MERGE"_hash:
        break;
      case "BASELINE-CONTROL"_hash:
        break;
      case "MKACTIVITY"_hash:
        break;
      case "BIND"_hash:
        break;
      case "SEARCH"_hash:
        break;

      default:
        qDebug() << "unknown header type";
        break;
    }

    event_->setHeader(header);
    event_->setSocket(socket);

    QCoreApplication::postEvent(qApp, event_, Qt::RealTimeEventPriority); // set network request event
    QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::X11ExcludeTimers); // process the network request event

    QtServiceBase::instance()->logMessage("Wrote to client");
  }
  catch(const char* error_message)
  {
    QtServiceBase::instance()->logMessage(error_message);
  }

  if(socket->isOpen())
    socket->close();
  if(socket->state() == QTcpSocket::UnconnectedState)
  {
    delete socket;
    QtServiceBase::instance()->logMessage("Connection closed");
  }
}
开发者ID:GravisZro,项目名称:kiwiengine,代码行数:101,代码来源:http_server.cpp


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