Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var options = new MyOptions();

            if (!Parser.Default.ParseArguments(args, options))
            {
                Console.WriteLine(options.GetUsage());
                return;
            }

            CdnOperate.ReadCdnConfig();

            var config = AppConfig.Instance();

            config.Rule               = "*.pkg*|*.pup*|*.json*";
            config.ConnType           = 0;
            config.LocalFileDirectory = options.LocalFolder;
            config.Port               = options.Port;
            config.IsAutoFindFile     = !string.IsNullOrEmpty(options.LocalFolder);

            var address = IPAddress.Parse(options.IPAddress);
            var port    = options.Port;

            _listener = new HttpListenerHelp(address, port, AddUrl);
            _listener.Start();

            Application.Run(new MyAppContext());
        }
Exemplo n.º 2
0
        /// <summary>
        ///     启动端口监听
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_start_Click(object sender, EventArgs e)
        {
            try
            {
                if (_listener != null)
                {
                    _listener.Dispose();
                    _listener       = null;
                    btn_start.Image = Resources.play;
                    btn_start.Text  = _rm.GetString("btn_start.Text");
                    _lw.Hide();
                    OpenLogToolStripMenuItem.Enabled = false;
                }
                else
                {
                    var address = IPAddress.Parse(cb_ip.Text);
                    var port    = int.Parse(tb_port.Text);
                    _listener = new HttpListenerHelp(address, port, _lw.AddUrl);
                    _listener.Start();

                    StartServer();
                    btn_start.Image = Resources.minus;
                    btn_start.Text  = _rm.GetString("stop");
                    Hide();

                    _lw.Show();
                    _lw.Activate();
                    OpenLogToolStripMenuItem.Enabled = true;
                }
                cb_ip.Enabled           = !cb_ip.Enabled;
                tb_port.Enabled         = !tb_port.Enabled;
                ckb_lixianspeed.Enabled = !ckb_lixianspeed.Enabled;
                ckb_loaclspeed.Enabled  = !ckb_loaclspeed.Enabled;
                cb_conntype.Enabled     = !cb_conntype.Enabled;
                ckb_cdn.Enabled         = !ckb_cdn.Enabled;
            }
            catch (Exception ex)
            {
                if (_listener != null)
                {
                    _listener.Dispose();
                    _listener = null;
                }

                MessageBox.Show(_rm.GetString("starterrorinfo") + ex.Message);
            }
        }
Exemplo n.º 3
0
        private void StartServer()
        {
            try
            {
                var address  = IPAddress.Parse(tb_Ip.Text);
                var port     = int.Parse(tb_Port.Text);
                var listener = new HttpListenerHelp(address, port, null);
                listener.Start();

                Thread.Sleep(2000);
                listener.Dispose();

                tb_Log.Text += "\n服务启动正常!";
            }
            catch (Exception ex)
            {
                tb_Log.Text += "\n服务启动异常!请修改IP地址或者端口号重新测试!\n错误信息:" + ex.Message;
            }
        }