public function receive()
    {
        // Read data from the socket
        socket_recv($this->socket, $msg, $this->buffer, MSG_DONTWAIT);

        if ($msg === false) {
            return null;
        }

        // Trim the padding from the message content
        $msg = trim($msg);

        // If message is not valid JSON, return it verbatim
        if (json_decode($msg) === null) {
            return $msg;
        }

        // Decode and return the message content
        return json_decode($msg);
    }