I looked through everything and can not find a solution to this problem. I tried every combination that I could see without luck.
Basically, I would like to choose an interface, start a UDP client on two machines and send / receive messages. Everything works fine when only one network adapter is active, but when they are active, it stops working. I looked with Wireshark and with one network adapter I could see how packets come and go.
Now, when I use two NICs, I can only TX from the first one enumerated and cannot get on any of them. WireShark does not show any received packets on the port for either of the two network adapters when they are both active.
The code is as follows. I used only one socket, but tried something else.
public UDPInstance(IPAddress ip, int port, int RXFrequency) { rxFreq = RXFrequency; // Listener Init TXclient = new UdpClient(); RXclient = new UdpClient(); TXclient.ExclusiveAddressUse = false; RXclient.ExclusiveAddressUse = false; //localEp = new IPEndPoint(ip, port); TXlocalEp = new IPEndPoint(ip, port); RXlocalEp = new IPEndPoint(IPAddress.Any, port); TXclient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); RXclient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); TXclient.Client.Bind(TXlocalEp); RXclient.Client.Bind(RXlocalEp); InterfaceIP = ip.ToString(); multicastaddress = IPAddress.Parse("239.0.0.222"); TXclient.JoinMulticastGroup(multicastaddress); RXclient.JoinMulticastGroup(multicastaddress); // Sender Init remoteep = new IPEndPoint(multicastaddress, port); Listener = null; RXData = new List<string>(); StartListenerThread(); } public void StartListenerThread() { Listener = new Thread(new ThreadStart(ListenerThread)); Listener.IsBackground = true; Listener.Start(); } public void StopListenerThread() { Listener.Abort(); } private void ListenerThread() { while (true) { Byte[] data = RXclient.Receive(ref remoteep); string datastr = Encoding.Unicode.GetString(data); if (datastr != "") { string[] PacketStrings = datastr.Split(new char[] { '~' }); foreach (string pkt in PacketStrings) RXData.Add(pkt); } Thread.Sleep(rxFreq); } } public void Transmit(string data) { byte[] buffer; buffer = Encoding.Unicode.GetBytes(data); TXclient.Send(buffer, buffer.Length, remoteep); }
source share