Understanding the Connection State Machine
It's important to at least understand how transitions occur in the connection state machine so you make decisions depending on what triggered each state. And to understand the subtle differences depending if you are Connecting
to another host or if you simply want to Listen for incoming connections. As you can see below the state machine for the NetworkConnection
is pretty simple.
All connections start in Disconnected
state.
- Depending what state the
NetworkDriver
is in, theListening (Passive)
state might be triggered. This is when the driver acts like a server listening for incoming connections and data requests. And secondly you could try to use the driver to connect to a remote endpoint and then we would invoke another flow of the state machine.
So to give a overview we have two standard scenarios. Either you listen for incoming connections or you use and outgoing connection to connect to someone else.
In our client/server workflow we use the ServerBehaviour to Listen
and the ClientBehaviour to Connect
.