Example #1
0
        public int CreateSocket(IPEndPoint ipEP, int index1, int index2)
        {
            NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
            UnicastIPAddressInformationCollection ipInf = interfaces[index1].GetIPProperties().UnicastAddresses;
            IPAddress localAddress = ipInf[index2].Address;

            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            try {
                socket.Bind(new IPEndPoint(localAddress, ipEP.Port));
            } catch (Exception) { return(-1); }

            MulticastOption mcastOpt = new MulticastOption(ipEP.Address, localAddress);

            socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, mcastOpt);
            socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastInterface, 0);
            UdpGroupSocketObject socketObj = new UdpGroupSocketObject();

            socketObj.socket      = socket;
            socketObj.remoteIpEP  = ipEP;
            socketObj.DisplayName = GetDisplayName(ipEP);
            socketObj.Parent      = this;
            socketObj.Children    = null;
            socketObjs.Add(socketObj);

            AsynchronousSocketListener.StartRead(socketObj);
            return(0);
        }
Example #2
0
        private void ShowUDPGroupView()
        {
            UDPGroupSocket       p1 = (UDPGroupSocket)socketModels[status.index1];
            UdpGroupSocketObject p2 = (UdpGroupSocketObject)p1.Children[status.index2];

            TLremoteIP.Visibility   = Visibility.Visible;
            TremoteIP.Visibility    = Visibility.Visible;
            TLremotePort.Visibility = Visibility.Visible;
            TremotePort.Visibility  = Visibility.Visible;
            TLlocalPort.Visibility  = Visibility.Visible;
            TlocalPort.Visibility   = Visibility.Visible;

            TLremoteIP.Text   = "组播地址: ";
            TLremotePort.Text = "组播端口: ";

            TremoteIP.Text   = p2.remoteIpEP.Address.ToString();
            TremotePort.Text = p2.remoteIpEP.Port.ToString();
            TlocalPort.Text  = TremotePort.Text;
        }