HTTP服务器软件系统的设计与实现(7)_毕业论文

毕业论文移动版

毕业论文 > 计算机论文 >

HTTP服务器软件系统的设计与实现(7)


            if (server != null)
            {
                server.Dispose();
                server = null;
            }
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            try
            {
                ///
                /// 创建HTTP提供者的服务器
                ///
                server = new WebServer<myLogger>();
                server.AddService<HttpService<myLogger>>(int.Parse(txtPort.Text));
                btnStart.Enabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }


        void Tracer_OnNewMessage(string message)
        {
            add2debug(message);
        }


        void add2debug(string message)
        {
            this.ltbDebug.Invoke((MethodInvoker)delegate
            {
                ltbDebug.Items.Add(message);
                ltbDebug.SelectedIndex = ltbDebug.Items.Count - 1;
            });
        }

        private void brnClear_Click(object sender, EventArgs e)
        {
            ltbDebug.Items.Clear();
        }
    }

    public class myLogger : IDebugger
    {
        public delegate void TraceMessageHandler(string message);
        public static event TraceMessageHandler OnNewMessage;

        public void trace(string log)
        {
            if (OnNewMessage != null)
                OnNewMessage(log); (责任编辑:qin)