2011-04-14 91 views
1

我設置了一個QTcpServer來監聽Shoutcast流。 newConnection() - 信號被觸發,因爲它應該:QTcpServer:發送HTTP/1.0 200 OK連接客戶端

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?

回答

1

當發出newConnection()信號時,必須使用nextPendingConnection()調用從QTcpServer中提取QTcpSocket對象。然後你必須在提取的QTcpSocket對象上調用writeData()。

這裏的關鍵在於偵聽套接字(QTcpServer)只負責每次新客戶端連接時創建連接套接字(或QTcpSocket)。 QTcpSocket負責與特定客戶端的實際通信。

也許你可以更具體什麼不適合你,你有什麼嘗試?如果您能爲我們提供wireshark PCAP,如果某些事情似乎沒有像預期的那樣工作,這也會很不錯。

+0

謝謝。它現在起作用,我不得不刪除換行符之間的空格。 – Hedge 2011-04-15 07:44:57