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; }
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; }
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 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 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; }