Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-43574

QWebSocket handshake bug

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P1: Critical P1: Critical
    • None
    • 5.3.2
    • WebSockets
    • None
    • Window Visual studio 2008 with QT 5.3.2, add-in 1.2.4

      I used QT5.3.2 and QWebSocket to connect with my server, everything works fine when my server is at local. But it fails to connect after I try to connect to any other server. I have found the reason why, that is, the handshake packet can't be processed correctly, here is the QT source code.

      void QWebSocketPrivate::processData(){
      
      Q_ASSERT(m_pSocket);
      while (m_pSocket->bytesAvailable()) {
          if (state() == QAbstractSocket::ConnectingState)
              processHandshake(m_pSocket.data());
          else
              m_dataProcessor.process(m_pSocket.data());
          }
      }
      
      void QWebSocketPrivate::processHandshake(QTcpSocket *pSocket)
      
      {
      for(int aa=0;aa<300000000;aa++)
          continue;
      ......
      /*parse packet header & content*/
      }
      

      The problem is, once there are bytes available to read in web socket, the m_pSocket->bytesAvailable() function will return true, even if these bytes are only part of the handshake packet. For example, the handshake packet looks like this (copy from wireshark)

      HTTP/1.1 101 Switching Protocols\r\n
      Date: Thu, 18 Dec 2014 09:16:22 GMT\r\n
      Upgrade: websocket\r\n
      Connection: Upgrade\r\n
      ......

      when the first line(HTTP/1.1 ...) has been read into the web socket, the m_pSocket->bytesAvailable() will return true, and the processHandshake will be invoked. But this will lead to a incomplete packet parsing in processHandshake so the connection won't be set up correctly. My workaround is adding a for loop at the beginning of processHandshake to wait for the whole packet been read into the web socket, so the parsing will succeed and the connection will set up correctly.

      Is this a bug of QT and is there any way to fix this problem?

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            kurt.pattyn Kurt Pattyn
            didayo yoyo
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes