Implement a rudimentary socket state machine.