简体   繁体   中英

Using specific network interface in C# with VLC ActiveX Plugin

I'm working now on the IPTV program in C#. As a media engine I'm using a VLC ActiveX Plugin. Data goes over UDP protocol.

Now I ran into the problem. I have several networking interfaces. For example, I have Local Area Connection, that is used for network and Internet access, and VirtualBox Network. First connection has an IP-address of 10.10.10.2 and second - 192.168.1.2. When I trying to join multicast-group, some of IGMP-queries go through the VirtualBox Network instead of Local Area Connection. So I don't receive a multicast-traffic.

I need to choose specific interface (Local Area Network) for my application. So all data will going through this network interface. I found some answers in the Internet, but not specifically for my problem.

Here's something, that I was trying to use:

IPAddress localAddress = IPAddress.Parse("10.10.10.2");
IPEndPoint localEndPoint = new IPEndPoint(localAddress, 0);
Socket client = new Socket(localEndPoint.AddressFamily, SocketType.Raw, ProtocolType.Igmp);
client.Bind(localEndPoint);
axVLCPlugin21.playlist.add("udp://@239.1.9.2:1234", axVLCPlugin21, null);
axVLCPlugin21.playlist.play();

But it's not working. Can someone help me, please?

Thank you!

I finally did it! I make a socket and bind it using my needed network interface. After that, I send IGMP-query using this socket and then receive data over needed network interface.

Now I'm using this code:

        Socket mcastSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
        IPAddress localAddress = IPAddress.Parse("10.10.10.2");
        IPEndPoint localEndPoint = new IPEndPoint(localAddress, 0);
        mcastSocket.Bind(localEndPoint);

        IPAddress mcastAddress = IPAddress.Parse("239.1.9.2");
        MulticastOption mcastOption = new MulticastOption(mcastAddress, localAddress);
        mcastSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, mcastOption);

        axVLCPlugin21.playlist.add("udp://@239.1.9.2:1234", axVLCPlugin21, null);
        axVLCPlugin21.playlist.play();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM