Rewriting connection state machine to support other protocols.