1

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

connect(tcpServer, SIGNAL(newConnection()), this, SLOT(handleClientComm()));

void IcecastServer::handleClientComm(){
    QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
    qDebug() << clientConnection->write("HTTP/1.0 200 OK\r\n\r\n" ) << endl;
    clientConnection->flush();
}

如何发送 HTTP 200 ?

4

1 回答 1

1

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

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

也许您可以更具体地说明什么对您不起作用以及您尝试过什么?如果某些东西似乎没有按预期工作,如果您可以为我们提供wireshark PCAP,那也很好?

于 2011-04-15T00:28:36.857 回答