         }
       } catch let err {
         self.log("\(id): Socket Read error: \(err)")
-        cont = false
+        cont = socket.isConnected
       }
     } while cont
     socket.close()

  func sendMessage(id:String, message:String, data:String) {
    let queue = DispatchQueue(label: "org.webpagetest.message", attributes: .concurrent)
    queue.async {
      self.sendMessageAsync("\(id) \(message) \(data)")
    }
  }
  

    if clientSocket != nil {
      self.log(">> \(message)")
      do {
        try clientSocket!.write(from:message)
      } catch let err {
        self.log("Socket write error: \(err)")
      }
