Hi, i’m currently working on a simple server to client communication in the local network, the “server” app shows the Ip address given by the router and the client use it to connect, then i can broadcast messages from my server to the clients:
SERVER START
MDriver = NetworkDriver.Create();
var endpoint = NetworkEndpoint.AnyIpv4;
endpoint.Port = this.Port;
if (MDriver.Bind(endpoint) != 0)
{
Debug.Log($"Failed to bind to port {Port}");
}
else
{
MDriver.Listen();
CLIENT CONNECTING
this.ip = _ip;
this.port = _port;
if (_isConnected) {
this.Disconnect();
}
var endpoint = NetworkEndpoint.Parse(ip, port);
Debug.Log($"CONNECTING TO {endpoint.Address}:{endpoint.Port}");
try
{
_isConnected = true;
statusTextContainer.GetComponent<TMP_Text>().text = $"Connesso a {ip}:{port}";
sfxStereo.GetComponent<AudioSource>().resource = this.pingConnection;
sfxStereo.GetComponent<AudioSource>().Play();
m_Connection = m_Driver.Connect(endpoint);
}
to make things easier i show the ip address on the server app with:
SHOW IP CODE
try
{
var host = Dns.GetHostEntry(Dns.GetHostName());
foreach (var ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
return {ip}:{this.Port};
}
}
return "Ip not found";
}
I tried this with my phone and pc in my wifi and it works without a problem, the ip is shown correctly and the client connects to the server which sends messages which arrive…
I then tried it with my girlfriend’s phone which has 4/5 years, and the shown ip is wrong!
it’s not the router ip and i’m certain of it because i checked it in the router interface AND if i connect using the one shown in the router ui the flow shown earlier works, but i dont understand why the ip shown is wrong…
SUMMARY AND CONTEXT:
-using Unity 6000
-on local network, home wifi
-it works on my phone and pc
-doesnt work on another phone
-both phones have the latest android OS
-the ip shown is wrong but if use the real ip it works, so the phone is connected to the wifi
-the phone data network is turned off, so it’s only connected to the wifi
-if i try to print all the addresses in the loop in debug mode it shows only one
is it a code problem? does the device need some settings i didn’t find?
thanks for the help!
