Пример #1
0
        public MainForm()
        {
            InitializeComponent();
            tsmiNetworkNew.Checked = true;

            var sIP   = "230.1.1.100";
            var nPort = 60100;

            // 从配置文件读取参数
            if (ConfigurationManager.AppSettings["Address"] != null)
            {
                var sConfig = ConfigurationManager.AppSettings["Address"];
                var items   = sConfig.Split(':');
                if (items.Length == 2)
                {
                    sIP   = items[0].Trim();
                    nPort = int.TryParse(items[1], out var port) ? port : nPort;
                }
            }

            // 开启接收线程
            new Thread(() =>
            {
                var hub = new RemoteHub("MapMonitor",
                                        group: new IPEndPoint(IPAddress.Parse(sIP), nPort),
                                        additions: new MulticastListener(
                                            pack => { if (tsmiNetworkNew.Checked)
                                                      {
                                                          mapBox1.UpdateRaw(pack.Command, pack.Payload);
                                                      }
                                            },
                                            201, 202));
                while (true)
                {
                    hub.Invoke();
                }
            })
            {
                IsBackground = true
            }.Start();

            // 旧网络
            udp = new Udp(sIP, nPort);
        }
Пример #2
0
        private void AddGroup()
        {
            var newHub = new RemoteHub(name: $"Monitor[{_memory}]", group: _memory);
            var node   = new GroupNode(newHub);

            Task.Run(() => {
                do
                {
                    var pack = newHub.Invoke();
                    if (pack != null)
                    {
                        this.Dispatch(_ => node.Receive(pack));
                    }
                } while (_endPoints.Contains(_memory));
            });
            Task.Run(() => new Pacemaker(_memory).Activate());

            Groups.Add(node);
        }