public static NetworkHost Create(Type interfaceType, NetworkHostConfig config)
 {
     return(new NetworkHost {
         Server = new NetworkGameServer(interfaceType, config.ServerConfig),
         Client = new NetworkGameClient(interfaceType, config.ClientConfig),
     });
 }
Beispiel #2
0
        // Host Methods

        /// <summary>
        /// Starts the local NetworkServer and NetworkClient, and connects the client to the
        /// local server.
        /// </summary>
        /// <remarks>
        /// This will open a connection and does not immediately resolve. To assure the
        /// connection is complete. Await the returned task.
        ///
        /// If a client is already active, another client will not be started.
        /// and the active client will be returned.
        /// </remarks>
        /// <param name="config">the NetworkHostConfig used to start the host.</param>
        /// <returns>an awaitable task for the resultant NetworkHost</returns>
        public async Task <NetworkHost> StartHost(NetworkHostConfig config)
        {
            StartServer(config.ServerConfig);
            StartClient(config.ClientConfig);
            await Client.Connect("localhost", (uint)config.ServerConfig.Port);

            return(Host);
        }
        // Host Methods

        /// <summary>
        /// Starts the local NetworkServer and NetworkClient, and connects the client to the
        /// local server.
        /// </summary>
        /// <remarks>
        /// This will open a connection and does not immediately resolve. To assure the
        /// connection is complete. Await the returned task.
        ///
        /// If a client is already active, another client will not be started.
        /// and the active client will be returned.
        /// </remarks>
        /// <param name="config">the NetworkHostConfig used to start the host.</param>
        /// <param name="interfaceType">INetworkInterface type to use, uses default if null.</param>
        /// <returns>an awaitable task for the resultant NetworkHost</returns>
        public async Task <NetworkHost> StartHost(NetworkHostConfig config, Type interfaceType = null)
        {
            var server = await StartServer(config.ServerConfig, interfaceType) as NetworkGameServer;

            if (Client != null)
            {
                StopClient();
            }
            Client = server.CreateLocalClient();
            return(Host);
        }