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

websocket server

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P2: Important P2: Important
    • None
    • 5.5.1
    • WebSockets
    • None
    • windows

      It was 2 weeks that i tried to connect an ESP8266 as websocket client to a qt server.
      But connection failed server never answer to my client handshake.

      I tried different server in python an java that worked. Yesterday handshake was successful after i connect a second client (using the websocket echo website). I think there is a trouble in the testing of the end of the http header.
      In fact my esp code is:

          client->tcp.write("GET ");
          client->tcp.write(client->cUrl.c_str(), client->cUrl.length());
          client->tcp.write(" HTTP/1.1\r\n"
                  "Host: ");
      
          client->tcp.write(_host.c_str(), _host.length());
          client->tcp.write("\r\n"
                  "Upgrade: websocket\r\n"
                  "Connection: Upgrade\r\n"
                  "User-Agent: arduino-WebSocket-Client\r\n"
                  "Sec-WebSocket-Version: 13\r\n"
                  "Sec-WebSocket-Protocol: arduino\r\n" // todo add api to set Protocol of Server
                  "Sec-WebSocket-Key: ");
      
          client->tcp.write(client->cKey.c_str(), client->cKey.length());
          client->tcp.write("\r\n");
      
          if(client->cExtensions.length() > 0) {
              client->tcp.write("Sec-WebSocket-Extensions: ");
              client->tcp.write(client->cExtensions.c_str(), client->cExtensions.length());
              client->tcp.write("\r\n");
          }
      
          // Header end wait for Server response
          client->tcp.write("\r\n");
      

      I think that Qt library dislike the fact that the tcp atomicity is not respect for the last "\r\n""\r\n" end of header.

      If it can help i send you log of my handshake:

      process(4): {GET }
      process(1): {/}
      process(17): { HTTP/1.1
      Host: }
      process(12): {192.168.0.13}
      process(160): {
      Upgrade: websocket
      Connection: Upgrade
      User-Agent: arduino-WebSocket-Client
      Sec-WebSocket-Version: 13
      Sec-WebSocket-Protocol: arduino
      Sec-WebSocket-Key: }
      process(24): {pbEvnd/byGV1KbV0dmCgaA==}
      process(2): {
      }
      process(2): {
      }
      

      I modify the esp library with the following code:

              String http_header;
      	http_header="GET "+client->cUrl+" HTTP/1.1\r\n";
              http_header+="Host: "+_host+"\r\n";
      	http_header+="Upgrade: websocket\r\n";
      	http_header+="Connection: Upgrade\r\n";
      	http_header+="User-Agent: arduino-WebSocket-Client\r\n";
      	http_header+="Sec-WebSocket-Version: 13\r\n";
      	http_header+="Sec-WebSocket-Protocol: arduino\r\n";
      	http_header+="Sec-WebSocket-Key: "+client->cKey+"\r\n";
      	
      	if(client->cExtensions.length() > 0) {
      		http_header+="Sec-WebSocket-Extensions: "+client->cExtensions+"\r\n";
          }
      	
      	http_header+="\r\n";
      	client->tcp.write(http_header.c_str(), http_header.length());
      

      and now it's work. I think that there is a problem in the frame cutting since connection is not rejected, no errror are detected and handshake is not detected.

      Hope to help community

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

            kurt.pattyn Kurt Pattyn
            jc87000 jean-clément durand
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes