Error while using QTcpSocket

前端 未结 2 1294
暗喜
暗喜 2020-12-20 07:59

I am creating a (very basic) MJPG server to show webcam data on a browser. I have partly managed to do it so far.

Here is my code:

TcpSe         


        
2条回答
  •  醉梦人生
    2020-12-20 08:45

    Here Is the Code I used to open the MJPEG Streaming Server in my original Project. Perhaps It can help you finding out your Problem.

    void MjpegStreamingEngine::StartServer(){
    
        m_TcpHttpServer = new QTcpServer();
    
        m_TcpHttpServer->connect(m_TcpHttpServer,
                                 SIGNAL(newConnection()),
                                 this,
                                 SLOT(TcpHttpconnected()));
    
        m_TcpHttpServer->listen(QHostAddress::Any,
                                8889);
    }
    
    void MjpegStreamingEngine::TcpHttpconnected(){
    
        m_TcpHttpClient = m_TcpHttpServer->nextPendingConnection();
    
        m_TcpHttpClient->connect(m_TcpHttpClient,
                                 SIGNAL(readyRead()),
                                 this,
                                 SLOT(TcpHttpreadyRead()));
    
    }
    
    void MjpegStreamingEngine::TcpHttpreadyRead(){
    
        m_TcpHttpClient->readAll(); // Discard "Get Request String"
    
        QByteArray ContentType = ("HTTP/1.0 200 OK\r\n" \
                                  "Server: en.code-bude.net example server\r\n" \
                                  "Cache-Control: no-cache\r\n" \
                                  "Cache-Control: private\r\n" \
                                  "Content-Type: multipart/x-mixed-replace;boundary=--boundary\r\n\r\n");
    
        m_TcpHttpClient->write(ContentType);
    
    
        while(1){
    
            if (m_TcpHttpClient->isOpen())
            {
    
                // Send Image
    
                QThread::msleep(10);
    
            }else{
                return;
            }
    
        }
    
        m_TcpHttpClient->disconnect(); //Should never be Reached
    }
    

提交回复
热议问题