QTcpServer: Send HTTP/1.0 200 OK to connected client

QTcpServer: Send HTTP/1.0 200 OK to connected client

本文关键字:OK to connected client Send HTTP QTcpServer      更新时间:2023-10-16

我设置了一个QTcpServer来收听一个广播流。newConnection()信号被触发,因为它应该:

connect(tcpServer, SIGNAL(newConnection()), this, SLOT(handleClientComm()));
void IcecastServer::handleClientComm(){
    QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
    qDebug() << clientConnection->write("HTTP/1.0 200 OKrnrn" ) << endl;
    clientConnection->flush();
}

如何发送HTTP 200

必须在发出newConnection()信号时使用nextPendingConnection()调用从QTcpServer中提取QTcpSocket对象。然后必须在提取的QTcpSocket对象上调用writeData()。

这里的关键是侦听套接字(QTcpServer)只负责在每次新客户端连接时创建连接套接字(或QTcpSocket)。QTcpSocket负责与特定客户端的实际通信。

也许你可以更具体地说什么对你不起作用,你尝试过什么?这也将是很好的,如果你能提供我们与wireshark PCAP,如果有些事情似乎不像预期的那样工作?