public override void ViewDidDisappear(bool animated)
        {
            base.ViewDidDisappear(animated);

            if (socketServer != null)
            {
                if (socketServer.State != SocketServerState.Stopped)
                {
                    socketServer.Stop();
                }

                socketServer.StateChanged -= SocketServer_StateChanged;

                socketServer.ReceivedMessage -= SocketServer_ReceivedMessage;

                socketServer.HostAcceptConnection -= SocketServer_HostAcceptConnection;

                socketServer.HostClosedConnection -= SocketServer_HostClosedConnection;

                socketServer = null;
            }

            if (socketBroadcastClient != null)
            {
                socketBroadcastClient.Dispose();

                socketBroadcastClient = null;
            }

            if (socketBroadcastServer != null)
            {
                if (socketBroadcastServer.State != SocketServerState.Stopped)
                {
                    socketBroadcastServer.Stop();
                }

                socketBroadcastServer.ReceivedMessage -= SocketBroadcastServer_ReceivedMessage;

                socketBroadcastServer = null;
            }
        }
        public override void ViewDidDisappear(bool animated)
        {
            base.ViewDidDisappear(animated);

            if (socketClient != null)
            {
                if (socketClient.State != SocketClientState.Disconnected)
                {
                    socketClient.Disconnect();
                }

                socketClient.StateChanged -= SocketClient_StateChanged;

                socketClient = null;
            }

            if (socketBroadcastServer != null)
            {
                if (socketBroadcastServer.State != SocketServerState.Stopped)
                {
                    socketBroadcastServer.Stop();
                }

                socketBroadcastServer.ReceivedMessage -= SocketBroadcastServer_ReceivedMessage;

                socketBroadcastServer = null;
            }

            if (socketBroadcastClient != null)
            {
                socketBroadcastClient.Dispose();

                socketBroadcastClient = null;
            }

            serverList.Clear();

            serverList = null;
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            btnStart.TouchUpInside += BtnStart_TouchUpInside;

            txtPort.ShouldReturn = SearchShouldReturn;

            socketServer = new SocketServer();

            socketServer.StateChanged += SocketServer_StateChanged;

            socketServer.ReceivedMessage += SocketServer_ReceivedMessage;

            socketServer.HostAcceptConnection += SocketServer_HostAcceptConnection;

            socketServer.HostClosedConnection += SocketServer_HostClosedConnection;

            socketBroadcastClient = new SocketBroadcastClient(BROADCAST_PORT);

            serverInfo = new ServerInfo();

            serverInfo.id = Guid.NewGuid();

            serverInfo.name = "Server Name";

            socketBroadcastServer = new SocketBroadcastServer();

            socketBroadcastServer.ReceivedMessage += SocketBroadcastServer_ReceivedMessage;
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.server_layout);

            lblServerStatus = FindViewById<TextView>(Resource.Id.lblServerStatus);

            txtPort = FindViewById<EditText>(Resource.Id.txtPort);

            btnStart = FindViewById<Button>(Resource.Id.btnStart);

            txtMessages = FindViewById<TextView>(Resource.Id.txtMessages);

            btnStart.Click += BtnStart_Click;

            txtPort.SetOnEditorActionListener(this);

            socketServer = new SocketServer();

            socketServer.StateChanged += SocketServer_StateChanged;

            socketServer.ReceivedMessage += SocketServer_ReceivedMessage;

            socketServer.HostAcceptConnection += SocketServer_HostAcceptConnection;

            socketServer.HostClosedConnection += SocketServer_HostClosedConnection;

            socketBroadcastClient = new SocketBroadcastClient(BROADCAST_PORT);

            serverInfo = new ServerInfo();

            serverInfo.id = Guid.NewGuid();

            serverInfo.name = "Test 3";

            socketBroadcastServer = new SocketBroadcastServer();

            socketBroadcastServer.ReceivedMessage += SocketBroadcastServer_ReceivedMessage;
        }
        protected override void OnDestroy()
        {
            base.OnDestroy();

            if (socketServer != null)
            {
                if (socketServer.State != SocketServerState.Stopped)
                {
                    socketServer.Stop();
                }

                socketServer.StateChanged -= SocketServer_StateChanged;

                socketServer.ReceivedMessage -= SocketServer_ReceivedMessage;

                socketServer.HostAcceptConnection -= SocketServer_HostAcceptConnection;

                socketServer.HostClosedConnection -= SocketServer_HostClosedConnection;

                socketServer = null;
            }

            if (socketBroadcastClient != null)
            {
                socketBroadcastClient.Dispose();

                socketBroadcastClient = null;
            }

            if (socketBroadcastServer != null)
            {
                if (socketBroadcastServer.State != SocketServerState.Stopped)
                {
                    socketBroadcastServer.Stop();
                }

                socketBroadcastServer.ReceivedMessage -= SocketBroadcastServer_ReceivedMessage;

                socketBroadcastServer = null;
            }

            serverInfo = null;

            txtMessages = null;

            lblServerStatus = null;

            txtPort = null;
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            tblServerList.RegisterNibForCellReuse (ServerTableViewCell.Nib, ServerTableViewCell.Key);

            serverList = new List<ServerInfo>();

            var serverListSource = new ServerListTableViewSource (serverList);

            serverListSource.SelectedItem += ServerListSource_SelectedItem;

            tblServerList.Source = serverListSource;

            tblServerList.ReloadData ();

            btnConnect.TouchUpInside += BtnConnect_TouchUpInside;

            txtIPAddress.ShouldReturn = SearchShouldReturn;

            txtPort.ShouldReturn = SearchShouldReturn;

            txtMessage.ShouldReturn = SearchShouldReturn;

            socketClient = new SocketClient();

            socketClient.StateChanged += SocketClient_StateChanged;

            socketBroadcastServer = new SocketBroadcastServer();

            socketBroadcastServer.ReceivedMessage += SocketBroadcastServer_ReceivedMessage;

            socketBroadcastServer.Run(BROADCAST_PORT);

            socketBroadcastClient = new SocketBroadcastClient(BROADCAST_PORT);
        }