Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QIODevice::write (QTcpSocket): device not open
Forum Update on Monday, May 27th 2025

QIODevice::write (QTcpSocket): device not open

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 805 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marek
    wrote on last edited by
    #1

    Hi
    I'm using qhttpengine in my server application to provide some API for React based website. I know it is old and I should switch to eg. Cutelyst
    After I have switched to SSL with this API I have a problem:
    When serwer is sending more data (like a 41kb PDF file encoded to Base64) QTcpSocket is being closed during transmission before I send the data, I can see in logs:

    Warning: 2021-09-09 10:39:06 QIODevice::write (QTcpSocket): device not open
    Debug: 2021-09-09 10:39:06 HttpServer::addHeadersAndWrite data.size 56843
    

    and user receives:

    Error: Transferred a partial file
    

    Without SSL, no problem.
    Where to look ? Is there some buffer size or something?
    I'm also using QSslSocket in other application and if I set dataSize variable to quint64, I can send big files.

    Best Regards
    Marek

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      How have your switched to ssl ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        How have your switched to ssl ?

        M Offline
        M Offline
        Marek
        wrote on last edited by
        #3

        @SGaist Hi

        By setting certificate in init function

        void HttpServer::init() {
            const char *post_method="POST";
            const char *put_method="PUT";
            const char *options_method="OPTIONS";
            handler.registerMethod(this->getEndpointString(EndpointGetClients), [](QHttpEngine::Socket *socket) {
                HttpServer *p=static_cast<HttpServer*>(Vr().httpServer);
                p->processConnection(socket,QHttpEngine::Socket::Method::GET,EndpointGetClients);
            });
           ....
           if(Vr().webUseSsl) {
                QFile keyFile(":/path_to.key");
                if(!keyFile.open(QIODevice::ReadOnly)) {
                    qWarning()<<"HttpServer::init can't open key";
                }
                QByteArray key_data=keyFile.readAll();
                QSslKey key(key_data, QSsl::Rsa,QSsl::Pem,QSsl::PrivateKey,QString("key_secret").toLocal8Bit().data());
                QList<QSslCertificate> certs = QSslCertificate::fromPath(":/path_to.crt");
        
                QSslConfiguration config;
                config.setPrivateKey(key);
                config.setLocalCertificateChain(certs);
        
                server.setSslConfiguration(config);
            }
        
            server.setHandler(&handler);
        
            if (!server.listen(QHostAddress(Vr().restApiIp),Vr().restApiPort)) {
                qCritical()<<"HttpServer::init unable to bind to a local port ip:"<<Vr().restApiIp<<" port:"<<Vr().restApiPort;
            } else {
                qDebug()<<"HttpServer::init listening on port:"<<server.serverPort();
            }
        }
        

        Best Regards
        Marek

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved