Esempio n. 1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ConnectionDB.CreateTables();

            IPAddress[] ips = null;
            ComName.Text = Dns.GetHostName();
            localName    = Dns.GetHostName();
            ips          = Dns.GetHostAddresses(ComName.Text);

            int i = 0;

            foreach (IPAddress one in ips)//筛选,只显示本机IPv4地址
            {
                if (one.AddressFamily == AddressFamily.InterNetwork)
                {
                    ComIP.Items.Add(one);
                    ipv4[i++] = one;
                }
            }
            //新开3个线程,1、监听其它主机的广播消息 2、广播 3、监听其它主机非广播的信息

            ThreadPool.QueueUserWorkItem(StartListenUdp);    //监听其它主机发的广播包

            ClassBroadCast broadCast = new ClassBroadCast(); //广播本机信息

            ThreadPool.QueueUserWorkItem(broadCast.BroadCast, localName);

            ThreadPool.QueueUserWorkItem(ReceiveNews);//监听其它主机非广播的信息

            //ThreadPool.QueueUserWorkItem(CheckUnread);
        }
Esempio n. 2
0
        private void Window_Closed(object sender, EventArgs e)
        {
            ClassBroadCast broadCast = new ClassBroadCast();        //广播本机退出的消息

            broadCast.Leave(localName);
            return;
        }