def send_msg(self, connection, data):
        """
        Function to send messages
        
        Parameters
        ----------
        connection: socket or connection
        data: data that can be serialized to json
        """
        # serialize as JSON
        msg = json.dumps(data)
        # Prefix each message with a 4-byte length (network byte order)
        msg = struct.pack('>I', len(msg)).decode() + msg
        connection.sendall(msg.encode())
        return