Skip to content
  • 0 Votes
    3 Posts
    1k Views
    F

    @Pablo-J.-Rogina
    Thanks for your reply. But in the article you mentioned said that we can authenticate socket via cookie, or pass authorization header when connecting, but in QWebsocketServer, we can only access "origin" in header, so we cannot authenticate socket before accepting connection.
    Furthermore , I think that authenticating socket after accepting connection is not a good way. Because attackers can initiate a lot of zombie websockets to connect to server, although these "zombie" do anything but they will occupy lots of resources of server.

  • WebSocket Services

    Unsolved General and Desktop
    4
    0 Votes
    4 Posts
    919 Views
    D

    Then you must be looking for the QWebSocketServer & QWebSocket classes.

    You will find some example projects in QtCreator directly if you search for "websocket" (or directly in the documentation).

    D

  • 0 Votes
    2 Posts
    2k Views
    siropS

    Ok, just solved it through trial and error.

    Had a messy QEventLoop and another place, which, however, was used during auth parsing.
    Now it looks like this:

    QNetworkAccessManager nam; QEventLoop loop; connect(&nam, &QNetworkAccessManager::finished, this, &RestConn::processReply); nam.get(*request); loop.connect(&nam, SIGNAL(finished(QNetworkReply*)),&loop, SLOT(quit())); loop.exec(QEventLoop::AllEvents);

    And before - in the error case - the last two lines did not follow in correct order as they were:

    // This order is not correct loop.exec(QEventLoop::AllEvents); loop.connect(&nam, SIGNAL(finished(QNetworkReply*)),&loop, SLOT(quit()));

    Thanks to all anyway.

  • 0 Votes
    2 Posts
    2k Views
    F

    I'm sorry, didn't realize that using deprecated qwebchannel.js ... problem solved.

  • 0 Votes
    2 Posts
    1k Views
    A

    Ok issue is solved.

    From my investigation it appears that the QWebSocketServer works properly only when communicating with the main thread.
    Therefore, any messages sent by other threads will not be received at the other side and the socket server will be corrupted from that moment.

    In order to fix this issue I actually forced any other thread in my application to send their messages using the main thread.
    I did it by using QMetaObject::invokeMethod() with Qt:QueuedConnection as the connection type.

    Hope this can help anyone in the future,

    Idan