handle both stdin and socket