Example #1
0
        /// <summary>
        ///     Connects to a remote server in the background.
        /// </summary>
        /// <param name="connection">The connection to use to connect to the server.</param>
        /// <param name="callback">The callback to invoke one the connection attempt has finished.</param>
        public void ConnectInBackground(NetworkClientConnection connection, ConnectCompleteHandler callback = null)
        {
            new Thread(
                delegate()
            {
                try
                {
                    Connect(connection);
                }
                catch (Exception e)
                {
                    callback?.Invoke(e);
                    return;
                }

                callback?.Invoke(null);
            }
                ).Start();
        }
Example #2
0
        /// <summary>
        ///     Connects the client using the given connection.
        /// </summary>
        /// <param name="connection">The connection to use to connect to the server.</param>
        public void Connect(NetworkClientConnection connection)
        {
            setupMutex.Reset();

            if (this.Connection != null)
            {
                this.Connection.Dispose();
            }

            this.Connection            = connection;
            connection.MessageReceived = MessageReceivedHandler;
            connection.Disconnected    = DisconnectedHandler;

            connection.Connect();

            //On timeout disconnect
            if (!setupMutex.WaitOne(10000))
            {
                Connection.Disconnect();
            }
        }