/// <summary>
        /// Raises the server state changed event.
        /// </summary>
        /// <param name="state">Server state.</param>
        protected void OnStateChanged(SocketServerState state)
        {
            this.state = state;

            var handler = StateChanged;

            if (handler != null)
            {
                handler(this, state);
            }
        }
        protected void SocketServer_StateChanged (object sender, SocketServerState state)
        {
            InvokeOnMainThread(() =>
                {
                    switch (state)
                    {
                        case SocketServerState.Starting:
                    
                            lblServerStatus.Text = "Starting";

                            lblServerStatus.TextColor = UIColor.Green;

                            btnStart.SetTitle("Stop", UIControlState.Normal);

                            break;

                        case SocketServerState.Running:

                            lblServerStatus.Text = "Running";

                            lblServerStatus.TextColor = UIColor.Green;

                            btnStart.SetTitle("Stop", UIControlState.Normal);

                            break;

                        case SocketServerState.Stopped:

                            lblServerStatus.Text = "Stopped";

                            lblServerStatus.TextColor = UIColor.Red;

                            btnStart.SetTitle("Start", UIControlState.Normal);

                            break;
                    }
                });
        }
        protected void SocketServer_StateChanged(object sender, SocketServerState state)
        {
            InvokeOnMainThread(() =>
            {
                switch (state)
                {
                case SocketServerState.Starting:

                    lblServerStatus.Text = "Starting";

                    lblServerStatus.TextColor = UIColor.Green;

                    btnStart.SetTitle("Stop", UIControlState.Normal);

                    break;

                case SocketServerState.Running:

                    lblServerStatus.Text = "Running";

                    lblServerStatus.TextColor = UIColor.Green;

                    btnStart.SetTitle("Stop", UIControlState.Normal);

                    break;

                case SocketServerState.Stopped:

                    lblServerStatus.Text = "Stopped";

                    lblServerStatus.TextColor = UIColor.Red;

                    btnStart.SetTitle("Start", UIControlState.Normal);

                    break;
                }
            });
        }
 /// <summary>
 /// Initializes a new instance of the server/> class.
 /// </summary>
 public SocketBroadcastServer()
 {
     this.state = SocketServerState.Stopped;
 }
        /// <summary>
        /// Raises the server state changed event.
        /// </summary>
        /// <param name="state">Server state.</param>
        protected void OnStateChanged(SocketServerState state)
        {
            this.state = state;

            var handler = StateChanged;

            if (handler != null)
            {
                handler(this, state);
            }
        }
        protected void SocketServer_StateChanged (object sender, SocketServerState state)
        {
            RunOnUiThread(() =>
                {
                    switch (state)
                    {
                        case SocketServerState.Starting:

                            lblServerStatus.Text = "Starting";
                            
                            lblServerStatus.SetTextColor(Color.Green);
                            
                            btnStart.Text = "Stop";

                            break;

                        case SocketServerState.Running:

                            lblServerStatus.Text = "Running";

                            lblServerStatus.SetTextColor(Color.Green);

                            btnStart.Text = "Stop";

                            break;

                        case SocketServerState.Stopped:
                            
                            lblServerStatus.Text = "Stopped";

                            lblServerStatus.SetTextColor(Color.Red);

                            btnStart.Text = "Start";

                            break;
                    }
                });
        }
        protected void SocketServer_StateChanged(object sender, SocketServerState state)
        {
            InvokeOnMainThread(() =>
                {
                    switch (state)
                    {
                        case SocketServerState.Starting:

                            lblServerStatus.Text = "Starting";

                            lblServerStatus.TextColor = UIColor.Green;

                            btnStart.SetTitle("Stop", UIControlState.Normal);

                            break;

                        case SocketServerState.Running:

                            lblServerStatus.Text = "Running";

                            lblServerStatus.TextColor = UIColor.Green;

                            btnStart.SetTitle("Stop", UIControlState.Normal);

                            serverInfo.started = ServerInfoState.Started;

                            socketBroadcastClient.SendMessage(SerializationHelper.ToByteArray(serverInfo));

                            socketBroadcastServer.Run(BROADCAST_PORT);

                            break;

                        case SocketServerState.Stopped:

                            lblServerStatus.Text = "Stopped";

                            lblServerStatus.TextColor = UIColor.Red;

                            btnStart.SetTitle("Start", UIControlState.Normal);

                            serverInfo.started = ServerInfoState.Stoped;

                            socketBroadcastClient.SendMessage(SerializationHelper.ToByteArray(serverInfo));

                            socketBroadcastServer.Stop();

                            break;
                    }
                });
        }
        protected void SocketServer_StateChanged(object sender, SocketServerState state)
        {
            RunOnUiThread(() =>
                {
                    switch (state)
                    {
                        case SocketServerState.Starting:

                            lblServerStatus.Text = "Starting";

                            lblServerStatus.SetTextColor(Color.Green);

                            btnStart.Text = "Stop";

                            break;

                        case SocketServerState.Running:

                            lblServerStatus.Text = "Running";

                            lblServerStatus.SetTextColor(Color.Green);

                            btnStart.Text = "Stop";

                            serverInfo.started = ServerInfoState.Started;

                            socketBroadcastClient.SendMessage(SerializationHelper.ToByteArray(serverInfo));

                            socketBroadcastServer.Run(BROADCAST_PORT);

                            break;

                        case SocketServerState.Stopped:

                            lblServerStatus.Text = "Stopped";

                            lblServerStatus.SetTextColor(Color.Red);

                            btnStart.Text = "Start";

                            serverInfo.started = ServerInfoState.Stoped;

                            socketBroadcastClient.SendMessage(SerializationHelper.ToByteArray(serverInfo));

                            socketBroadcastServer.Stop();

                            break;
                    }
                });
        }