Hi,
The title says it all but I’ll elaborate.
I’m learning to use the UNet network and some of parts the design of creating the connection between client and server confuse me.
You see, when you start a server in UNet you just use the static class NetworkServer and call Listen(). Everything is static so there is no ambiguity there.
But when you want to connect a client to a server you first have to create a new (non-static) NetworkClient object and then connect this NetworkClient instance to the server using Connect().
So:
-
Why do we have to instantiate a NetworkClient at all? This suggest that we might want to have multiple NetworkClient instances in the same game process. If so, what is the use of it (connecting to multiple servers?)?
-
If we really can have multiple
connections how does this play with
NetworkBehaviour synchronisation? How
do NetworkBehaviours know on which
connection to serialize to? -
Since NetworkClients are instanciated
do I need to keep a reference of
their instance if I want to keep the
connection? Otherwise my impression
would be that the connection will be
garbage-collected. -
Regarding my previous question, I’ve found the NetworkClient.allClients
array variable, a static array listing all NetworkClient instances. Would setting this variable to null then trigger a garbage-collect of the client connections?
I just can’t get my head around why would a static class suffice for the Server but not for the Client.
For whoever takes the time to answer: Thank you very much!