- Home /
UNET cannot connect android devices.
Im using UNET to make a wifi multiplayer game. I can connect two PCs just fine, however not two android devices, and not pc to android... the weird thing is that the match will show (using NetworkDiscovery) however it cannot connect (can only connect on pc to pc).
i believe the issue is as below: the serverIp variable is being set as "localhost" not the ip of the device.
public void Initialize(NetworkBroadcastResult value) {
string dataString = BytesToString (value.broadcastData);
var items = dataString.Split(':');
if (items.Length == 3 && items [0] == "NetworkManager") {
if (NetworkManager.singleton != null && NetworkManager.singleton.client == null) {
serverIp = items [1];
serverPort = Convert.ToInt32 (items [2]);
//NetworkManager.singleton.networkAddress = items [1];
NetworkManager.singleton.serverBindToIP = true;
NetworkManager.singleton.serverBindAddress = Network.player.ipAddress;
//NetworkManager.singleton.networkPort = Convert.ToInt32 (items [2]);
}
}
GetComponent<Button> ().onClick.AddListener (() => Connect());
}
//when the ui button is clicked..
//the serverIp shows as localhost rather than the ip of the device. i believe this is the issue..
public void Connect() {
NetworkManager.singleton.networkAddress = serverIp;
NetworkManager.singleton.networkPort = serverPort;
NetworkManager.singleton.StartClient ();
}
Answer by thornekey · May 14, 2017 at 11:59 AM
Solved it. For anyone in the future i hope i can help you:
instead of using serverIp = items [1]; for the Ip use value.serverAddress;
I am making my own NetworkDiscovery and didnt want the crappy UI that Unity supplies this is the reason for why i was making it. https://bitbucket.org/Unity-Technologies/networking/src/78ca8544bbf4e87c310ce2a9a3fc33cdad2f9bb1/Runtime/NetworkDiscovery.cs?at=5.3&fileviewer=file-view-default is the link to the NetworkDiscovery. Take a look at line 391 forloop, this is where theplayer pushes the connect button. Change the line NetworkManager.singleton.networkAddress = items[1]; to NetworkManager.singleton.networkAddress = value.serverAddress;, if youre building a custom NetworkDiscovery script.