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();
}
How do I send HTTP 200 ?
I set up a QTcpServer to listen to a Shoutcast stream. The newConnection()-signal gets fired as it should:
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();
}
How do I send HTTP 200 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当 newConnection() 信号发出时,您必须使用 nextPendingConnection() 调用从 QTcpServer 中提取 QTcpSocket 对象。然后您必须对提取的 QTcpSocket 对象调用 writeData()。
这里的关键是监听套接字(QTcpServer)只负责在每次新客户端连接时创建连接套接字(或QTcpSocket)。 QTcpSocket 负责与特定客户端的实际通信。
也许您可以更具体地说明什么对您不起作用以及您尝试过什么?如果某些事情似乎没有按预期工作,如果您能为我们提供wireshark PCAP,那就太好了?
You must extract QTcpSocket object from QTcpServer with nextPendingConnection() call when the newConnection() signal was emitted. And then you must call writeData() on the extracted QTcpSocket object.
The key here is that Listening socket (QTcpServer) is only responsible for creating Connection Sockets (or QTcpSocket) each time a new client connects. And the QTcpSocket is responsible for the actual communication with a specific client.
Maybe you can be more specific what exactly does not work for you and what have you tried? It would also be nice if you could provide us with wireshark PCAP if something does not seem to work as expected?