_udpAddr = IPAddress.Parse("228.5.6.9");
var port = 3333;
IPAddress localAddr = IPAddress.Any;
// Create endpoints
_remoteEndPoint = new IPEndPoint(_udpAddr, port);
_localEndPoint = new IPEndPoint(localAddr, port);
// Create and configure and bind UdpClient
_udpclient = new UdpClient(_localEndPoint);
// Join
_udpclient.JoinMulticastGroup(_udpAddr, localAddr);
// Start listening for incoming data
_udpclient.BeginReceive(new AsyncCallback(ReceivedCallback), null);
This is my UDP Multicast join code.
This code works fine on Xamarin UWP App and WIFI Connect only Android devices.
But, when Android devices connected to WIFI and LTE, device can't receive & send anything.
So, I changed LocalEndPoint setting like this,
...
....
//IPAddress localAddr = IPAddress.Any;
IPAddress localAddr = IPAddress.Parse(GetLocalIPAddress());
....
..
public static string GetLocalIPAddress()
{
var host = Dns.GetHostEntry(Dns.GetHostName());
foreach (var ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork
&& ip.ToString().Contains("192.168."))
{
return ip.ToString();
}
}
throw new Exception("Local IP Address Not Found!");
}
With this code, every Android device send works fine, but receive nothing.
The interesting thing is the both code works fine on UWP App.
UWP App can send & receive using any LocalEndpoint.
How Can Multicast join on Android devices connected to WIFI and LTE?