title: Qt Socket not waiting for bytes written
body: <p>I wrote a chess client/server mobile application and have a remote server that has been tested on the West Coast, the East Coast, in between, etc. The program is this in a nutshell:</p>
  
  <pre><code>1.  Log in to remote server with correct username/password via iOS/Android or Windows desktop.
  2.  Enter queue for a 1-minute, 5-minute or 30-minute game of chess.
  3.  Wait for another opponent to join queue.
  4.  Get matched and play game of chess.
  5.  When game is over, log out or play more chess.
  </code></pre>
  
  <p>I am getting the weirdest freaking error when I log in to the server via my school's internet, however.  This is so weird because it the ONLY ISP that has problems out of the many ISP's I have connected from.</p>
  
  <p>When I log into the server through my school's internet, I will get the following error and errorString from my socket.</p>
  
  <pre><code>QAbstractSocket::UnknownSocketError "Unknown error"
  </code></pre>
  
  <p>The steps to produce this in my application are:</p>
  
  <pre><code>1. Enter username and password, log into server. (Successfully completes this).
  
  2. Click to join a queue for a game of chess.  (Successfully writes to socket, but fails to wait for bytes written then emits the above error and error string.
  </code></pre>
  
  <p>I checked the server and readyRead() is not even called, so I know the client is not sending anything to the server.</p>
  
  <p>The funny thing is, I found a workaround for getting past this error.</p>
  
  <pre><code>1.  Click on Settings page.
  2.  Click Save. (Does the exact same thing as I try to do above.  Write to socket, flush and wait for bytes written).
  3.  Join queue (Successfully joins queue).
  </code></pre>
  
  <p>The workaround MAKES NO SENSE since it does not do anything differently than what I tried to do above (write to socket, flush and wait for bytes written).</p>
  
  <p>Does anyone have a clue on what might be going on?</p>
  
  <ol>
  <li>Why is this error specific to ONE internet location?  My school internet is slow as hell, but doesn't explain why the socket is disconnected immediately in the function below.</li>
  <li>Why does my workaround work?</li>
  <li>What can I do to learn more about my problem (i.e. stupid error message..."unknown error").</li>
  <li>Not only this, but when I right-click on the function below, then click 'Find usages', the build folder appears. This is the only function in the program that does this.  WTF???</li>
  </ol>
  
  <p><strong>Socket disconnects in this function.</strong></p>
  
  <pre><code> void CG_serverConnection::sendQueueType(int timeControl)
   {
      //Create local JSON object
      QJsonObject userInfo;
  
      //Create object
      userInfo["PacketHeader"] = QUEUE_REQUEST;
      userInfo["TimeControl"] = timeControl;
  
      //Create JSON document
      QJsonDocument doc;
      doc.setObject(userInfo);
  
      qDebug() &lt;&lt; "Send queue type called! ";
      qDebug() &lt;&lt; doc.toJson();
  
      QByteArray byteArray = doc.toBinaryData();
  
      //Send over socket
      if(m_socket-&gt;write(byteArray))
      {
          qDebug() &lt;&lt; "Wrote to socket";
      }
      else
          m_socket-&gt;errorString();
      if(m_socket-&gt;flush())
      {
          qDebug() &lt;&lt; "Flushed";
      }
      else
          qDebug() &lt;&lt; m_socket-&gt;errorString();
  
      if(m_socket-&gt;waitForBytesWritten(50000))
      {
          qDebug() &lt;&lt; "Bytes were written.";
      }
      else
      {
         qDebug() &lt;&lt; m_socket-&gt;error();
         qDebug() &lt;&lt; m_socket-&gt;errorString();
      }
  }
  </code></pre>
  
  <p><strong>Where I call the function</strong></p>
  
  <pre><code>    Button
      {
          id: btn_oneMinuteGame
          text: "One Minute"
          style: cgButtonStyle
  
          Layout.alignment: Qt.AlignCenter
          Layout.preferredWidth: Lobby.getControlWidth()
          Layout.preferredHeight: Lobby.getControlHeight()
  
          onClicked:
          {
              ServerConnection.sendQueueType(1) // TODO : Magic numbers
              root.startOneMinuteGame()
          }
      }
  </code></pre>