Split server functionality out into a trait.

One point of contention: I did not want to define the constructor in the trait, so I added the `setLoop` function to the trait. Not sure if that is the best solution.