Plugin for Mirage.
Multiplex allows a server to run multiple sockets at once, this allows clients from multiple platforms to connect to the same game server.
- Add openupm registry. Click on the menu Edit -> Project settings..., and add a scoped registry like so:
Name:OpenUPM
Url:https://package.openupm.com
Scopes:com.miragenet
- Close the project settings
- Open the package manager.
- Click on menu Window -> Package Manager and select "Packages: My Registries",
- select the latest version of
MultiplexSocketand click install, like so: - You may come back to the package manager to unistall
MultiplexSocketor upgrade it.
- On the
GameObjectthat contains yourNetworkManagercomponent, add theMultiplexSocketFactorycomponent. - Add other
SocketFactorycomponents that you want to use to the same or otherGameObjects. For example,UdpSocketFactoryandSteamSocketFactory. - In the Inspector for
MultiplexSocketFactory, expand theFactorieslist. - Drag and drop your other
SocketFactorycomponents (e.g.,UdpSocketFactory) into the list elements. The order of this list is important for clients. - Finally, assign the
MultiplexSocketFactorycomponent to theSocket Factoryfield on yourNetworkServerandNetworkClientcomponents.
The MultiplexSocketFactory behaves differently depending on whether it is running on a server or a client.
When a server is started, the MultiplexSocketFactory iterates through the entire Factories list and creates a server socket for each one. This allows the server to listen for connections on multiple transports at the same time. For example, a single server can accept connections from local LAN players using UDP and from Steam friends using Steam's transport layer simultaneously.
When a client starts, the MultiplexSocketFactory iterates through the Factories list in order and uses the first one that is supported on the current platform (IsSupported property returns true). This creates a fallback system. For example, if you place a Steam transport first in the list and a UDP transport second:
- If the client has Steam running, it will use the Steam transport to connect.
- If Steam is not running or not supported, the factory will fall back and try to use the UDP transport instead.