QTcpServer:向连接的客户端发送HTTP / 1.0 200 OK

问题描述

| 我设置了一个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?     

解决方法

发出newConnection()信号时,必须使用nextPendingConnection()调用从QTcpServer中提取QTcpSocket对象。然后,必须在提取的QTcpSocket对象上调用writeData()。 这里的关键是,每次新客户端连接时,侦听套接字(QTcpServer)仅负责创建连接套接字(或QTcpSocket)。 QTcpSocket负责与特定客户端的实际通信。 也许您可以更具体地说明到底什么对您不起作用,您尝试了什么?如果某些事情似乎无法按预期工作,那么您可以向我们提供wireshark PCAP也很好吗?     

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...