- Home /
PC Android LAN Network Connection
At the moment I am trying to create a networked game that works on both PC and Android (IOS to be supported later). The goal is to use mobile client devices as spectators for events while the main game plays out on the PC clients.
At the moment I have no issue networking between PCs and between multiple instances of a program run on the same PC. Using network discovery I am able to see connections broadcasted from PC hosts on Android clients but I am unable to connect. After a few seconds the connection times out and the connection message in the default Network Manage HUD is something like "connecting to local host...". Currently I am working with the sample program here as a base for the test. It should also be noted that PC clients are unable to find Android hosts when listening for broadcasts.
My current hunch is that somehow I need to open a port on the mobile device but I can't seem to find how to do this in Unity. It is important that this is done simply since Android users likely wont want to open settings to get the application to work. I've tried looking at a few tutorials for controllers however these seem to use the deprecated networking system which is no longer an option in my current Unity environment. Any advice or suggestions would be greatly appreciated. Apologize for being a bit vague but for legal reasons I can't or probably shouldn't post any code.
I have the same problem and I also want to do a game playing on the PC but using phones as controllers. I can't find any tutorial on how to do that, please tell me if you find a solution
Answer by Bioninja01 · Dec 10, 2019 at 04:28 AM
You might want to look here at this thread if you are still looking for an answer. He solution worked for me.
@Joe-Censored said the following:
Localhost is your problem. You need to connect to the ip address of the host computer. localhost (which is the same as connecting to 127.0.0.1) means connect to the computer I am on. Run ipconfig or ifconfig on your host computer to see what IP address it is using, and on your clients you connect to that. If you are trying to connect with another computer over the internet it is far more complicated, where you'll need to log into your router and find its IP address and port forward to your host computer.
This is not the issue. The link posted above helped and I was able to get the IP of my android device and connect my PC (the client) to my mobile device (the host/server) successfully. However, when in reverse (connecting my mobile device - the client - to my PC - the host/server), I was unable to get a connection. Is there something on android devices that doesnt allow the device to connect to a server. No connection occurs either way with two android devices either. I'm currently using $$anonymous$$irror to do my multiplayer, however $$anonymous$$irror, from my knowledge, doesnt support $$anonymous$$atchmaking, which the deprecated $$anonymous$$ultiplayer HPLAYI unity package did. If anyone has any tips on how to establish a connection between two android devices using $$anonymous$$irror, it would be gladly appreciated. Thanks!
BTW: This is the code for getting the IP of your device/PC, credit goes to some other guy on these forums:
public string LocalIPAddress()
{
IPHostEntry host;
string localIP = "";
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
localIP = ip.ToString();
//IP.text = localIP.ToString();
break;
}
}
return localIP;
}