Exemplo n.º 1
0
        private void p5_cmd_handler(IPEndPoint remote, Cmd cmd_base)
        {
            if (cmd_base is BroadcastIpListCmd)
            {
                BroadcastIpListCmd cmd = cmd_base as BroadcastIpListCmd;
                int size = cmd.ips == null ? 0 : cmd.ips.Length;
                for (int i = 0; i < size; i++)
                {
                    ConfirmIpCmd ack = new ConfirmIpCmd();
                    ack.ip          = cmd.ips[i];
                    ack.sender_name = this_name;
                    _p2_udp_peer.SendMessage(
                        new IPEndPoint(IPAddress.Parse(ack.ip), remote.Port),
                        ack);
                }
            }
            else if (cmd_base is BroadcastAddressCmd)
            {
                if (_p5_tcp_client != null && _p5_tcp_client.Connected)
                {
                    return;
                }

                BroadcastAddressCmd cmd = cmd_base as BroadcastAddressCmd;

                Helper.set_text(this.lblP5Ip, string.Format("{0}:{1}", cmd.ip, cmd.port));

                Task.Factory.StartNew(() =>
                {
                    start_p5_tcp_client();
                    connect_p5_tcp_client(cmd.ip, cmd.port);
                });
            }
        }
Exemplo n.º 2
0
        private void p1_udp_timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            IEnumerable <string> ipv4s = Helper.get_localhost_ipv4();
            BroadcastIpListCmd   cmd   = new BroadcastIpListCmd();

            cmd.sender_name = this_name;
            cmd.ips         = ipv4s == null ? null : ipv4s.ToArray();

            //向P2进行多播
            _p1_udp_peer.SendMessage(
                new IPEndPoint(_p1_udp_peer.MulticastAddress, Helper.p2_udp_port),
                cmd);

            //向P3进行多播,目前先不加入
            //todo

            //向P4进行多播
            _p1_udp_peer.SendMessage(
                new IPEndPoint(_p1_udp_peer.MulticastAddress, Helper.p4_udp_port),
                cmd);
        }