Ejemplo n.º 1
0
        /// <summary>
        /// Starts this instance.
        /// </summary>
        public void Start()
        {
            string msg;

            new Task(() =>
            {
                while (true)
                {
                    try
                    {
                        msg = m_reader.ReadString();
                        if (msg != null)
                        {
                            DataReceived?.Invoke(this, new DataReceivedEventArgs(msg));
                        }
                    }
                    catch (Exception e)
                    {
                        MessageCommand mc = new MessageCommand();
                        mc.CommandID      = -1;
                        mc.CommandMsg     = e.Message;
                        DataReceived?.Invoke(this, new DataReceivedEventArgs(mc.ToJSON()));
                        Close();
                        break;
                    }
                }
            }, m_cancelToken.Token).Start();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Closes this instance.
        /// </summary>
        public void Close()
        {
            MessageCommand mc = new MessageCommand();

            mc.CommandID = (int)CommandEnum.CloseServerCommand;
            SendAll(mc.ToJSON());
            foreach (ClientHandler client in clients)
            {
                client.Close();
            }
        }