/// <summary> /// opens communication protocol- server starts listening to clients. /// </summary> public void Start() { m_logging.AddEvent(delegate(Object sender, MessageRecievedEventArgs e) { string[] logs = { e.Status.ToString() + " " + e.Message }; CommunicationProtocol msg = new CommunicationProtocol((int)CommandEnum.GetLogCommand, logs); InformClients(msg); }); //string ip = ConfigurationManager.AppSettings["IP"]; //int port = int.Parse(ConfigurationManager.AppSettings["Port"]); //IPEndPoint ep = new IPEndPoint(IPAddress.Parse(ip), port); IPEndPoint ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8000); listener = new TcpListener(ep); listener.Start(); m_logging.Log(Messages.ServerWaitsForConnections(), MessageTypeEnum.INFO); Task task = new Task(() => { while (this.serverIsOn) { try { TcpClient client = listener.AcceptTcpClient(); ch.HandleClient(client); this.allClients.Add(client); } catch (SocketException) { m_logging.Log(Messages.ServerCouldntAcceptClient(), MessageTypeEnum.FAIL); break; } } m_logging.Log(Messages.ServerStopped(), MessageTypeEnum.INFO); }); task.Start(); this.imagesPort.Start(); }
/// <summary> /// adds a ILoggingService event handler. /// </summary> /// <param name="func">event handler: function to be called when the event /// is invoked</param> public void AddEvent(EventHandler <MessageRecievedEventArgs> func) { m_logging.AddEvent(func); }