I'd like to limit the temporary file usage.  The way to avoid most temporary file usage would be to do something like this (untested; comments/debug/error prints omitted for brevity):
```
{
    if [ "$current" = ':0' ]; then
        echo -n 'R' | websocketcommand
    else
        echo -n 'R'
        DISPLAY="$current" xclip -o -sel clip
    fi
} | (
    STATUS="`head -c 1`"
    if [ "$STATUS" != 'R' ]; then
        exit 0
    fi
    if [ "$next" = ':0' ]; then
        STATUS="`(echo -n 'W'; cat) | websocketcommand`"
        if [ "$STATUS" != 'WOK' ]; then
            exit 1
        fi
    else
        tmpfile="`mktemp`"
        trap "rm -f '$tmpfile'" 0
        cat > "$tmpfile"
        if ! DISPLAY="$next" xclip -o -sel clip | diff -q - "$tmpfile" >/dev/null; then
            DISPLAY="$next" xclip -i -sel clip "$tmpfile"
        fi
    fi
) && current="$next"

Can't think of a way to not need a temporary file for the second one.