Options to manage connections between server and clients
Closed this issue · 1 comments
loherangrin commented
Multiple client runtimes can connect to a single server runtime. This requires that:
- all clients knows the server address (IP address and port);
- a valid network is established between all runtimes, if they are started in separate containers.
Moreover, since all runtimes use the same project directory, only one instance of AssetProcessor must be run and shared between all running runtimes in order to avoid collisions while processing asset files.
Need to edit the behavior of run
command to automate the previous steps to let users to insert network values only once. In particular:
- an
O3TANKS_NETWORK
environment variable accepts the identifier of the required network. Users have to create the network prior using it, since there are too many scenarios to address in order to automate the process (e.g. an internal-only network, a bridged network with full / limited internet access, ...). If set tonone
, all runtimes are run inside a single container with no network access; - when AssetProcessor is executed by the first runtime, it registers a lock file at
.o3tanks/private/asset-processor.json
with all its network information (container ID, IP address, port). Other runtimes can then retrieve these data and connect to it directly, without creating a new instance. Sanity checks are required on retrieved data (e.g. container still exists) since the AssetProcessor container may crash without removing the lock file; - AssetProcessor need to be configured to accept connection from IP addresses in the chosen network;
- a
--listen <port>
option forrun server
command sets the port where the server has to listen for new connections and activate it automatically. Value must be checked before being used to be sure that the port isn't already in use. If not provided, the first random port starting from the default one (33450
) is used; - when a server is executed, it registers a lock file at
.o3tanks/private/server.json
using the same behavior of AssetProcessor; - a
--connect
option forrun client
command activates auto-connection when the client is started. Server address is retrieved from the server lock file, or an error is thrown if no server is running. - a
--connect <ip>:<port>
option forrun client
command skips the server auto-discovery and connects to any provided address. It is useful to support generic scenarios where the server is running on a remote machine.
Note that also open
command is impacted since Editor requires an instance of AssetProcessor (step 2).
loherangrin commented
Added instructions to use the new options in the cookbook:
Run a multiplayer project in a container network