Wrote most of the client listener thread.