Esempio n. 1
0
        /// <summary>
        /// Creates a new client. There can only be one client instance per application.
        /// The client can connect to a locally running server or to a remote server.
        /// Note that this does not connect the client to any server, only prepare it for use.
        /// The configuration allows for deeper optimization of the client.
        /// </summary>
        /// <param name="config">The configuration that the client will use.</param>
        public static void StartClient(NetPeerConfiguration config)
        {
            if (!Initialized)
            {
                Error("Call Init() before starting the client.");
                return;
            }

            if (IsClient)
            {
                Error("Client already created!");
                return;
            }

            if (config == null)
            {
                Error("Config cannot be null, client not created.");
                return;
            }

            try
            {
                JNetClient c = new JNetClient(config);
                c.Start();
                JNet.Client = c;

                Log("Client created and ready to connect.");
            }
            catch (Exception e)
            {
                throw new JNetException(string.Format("Exception creating client. See inner exception ({0})", e.GetType().FullName), e);
            }
        }
Esempio n. 2
0
        public static void ShutdownClient(string bye)
        {
            if (!Initialized)
            {
                Error("Call Init() before disconnecting down the client.");
                return;
            }

            if (!IsClient)
            {
                Error("Client is not created yet, cannot disconnect!");
                return;
            }

            if (Client.ConnectionStatus == NetConnectionStatus.Connected)
            {
                DisconnectClient(bye);
            }

            Client = null;
        }