开发者

QTcpServer: Send HTTP/1.0 200 OK to connected client

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()))开发者_Python百科;

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 ?


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜