public NetworkGameClient(Type interfaceType, NetworkClientConfig config)
 {
     NetworkInterface = (INetworkInterface)Activator.CreateInstance(interfaceType);
     NetworkInterface.OnPeerDisconnected += OnPeerDisconnected;
     NetworkInterface.Initialize(new NetworkInterfaceConfiguration {
         Type = NetworkInterfaceType.Client
     });
 }
        // Client Methods

        /// <summary>
        /// Starts the local NetworkClient.
        /// </summary>
        /// <remarks>
        /// This does not connect the client to any server. This only opens the
        /// socket for a client.
        ///
        /// If a client is already active, another client will not be started.
        /// and the active client will be returned.
        /// </remarks>
        /// <param name="config">the NetworkClientConfig used to start the server.</param>
        /// <param name="interfaceType">INetworkInterface type to use, uses default if null.</param>
        /// <returns>the NetworkClient created or fetched.</returns>
        public INetworkClient StartClient(NetworkClientConfig config, Type interfaceType = null)
        {
            if (Client != null)
            {
                return(Client);
            }
            interfaceType = interfaceType ?? DefaultNetworkInterfaceType;
            Client        = new NetworkGameClient(interfaceType, config);
            return(Client);
        }
        public async void StartClient()
        {
            var networkManager = NetworkManager.Instance;
            var clientConfig   = new NetworkClientConfig();
            var client         = networkManager.StartClient(clientConfig);

            Debug.Log($"Connecting to {IP.text}:{PortValue}");
            try {
                SetActive(ConnectingScreen);
                await client.Connect(IP.text, PortValue);
            } catch (NetworkingException exception) {
                networkManager.StopClient();
                SetActive(ErrorScreen);
                ErrorText.text = exception.Message;
                Debug.LogError(exception);
                return;
            }
            SetActive(SuccessScreen);
        }
示例#4
0
 public NetworkGameClient(Type interfaceType, NetworkClientConfig config)
 {
     NetworkInterface = (INetworkInterface)Activator.CreateInstance(interfaceType);
     NetworkInterface.Initialize(0);
 }
示例#5
0
        // Client Methods

        /// <summary>
        /// Starts the local NetworkClient.
        /// </summary>
        /// <remarks>
        /// This does not connect the client to any server. This only opens the
        /// socket for a client.
        ///
        /// If a client is already active, another client will not be started.
        /// and the active client will be returned.
        /// </remarks>
        /// <param name="config">the NetworkClientConfig used to start the server.</param>
        /// <returns>the NetworkClient created or fetched.</returns>
        public INetworkClient StartClient(NetworkClientConfig config)
        {
            return(Client ?? (Client = new NetworkGameClient(NetworkInterfaceType, config)));
        }