You can't do it with just the iMac - that port is output only. You can sort of do it over USB with an adapter like one of
these, but those that have tried it seem to think that experience is less than optimal, as the latency is too high. Caveat emptor.