         if !socket.isConnected {
             connectWithToken()
         }
-        operations.addOperationWithBlock {
-            self.socket.writePing(data)
+        if !isClosedByError {
+            operations.addOperationWithBlock { self.socket.writePing(data) }
         }
     }
 

        if !socket.isConnected {
            connectWithToken()
        }
        operations.addOperationWithBlock {
            self.socket.writeString(str)
        }
    }


        if !socket.isConnected {
            connectWithToken()
        }
        if !isClosedByError {
            operations.addOperationWithBlock { self.socket.writeData(data) }
        }
    }

