- Home /
Simple Networking code does not work
Hey, i've got this code from a tutorial on youtube, and i dont know why it does not work. When i've got a server in the editor, and i do connect as client in the exe, nothing happens..
public string IP ="86.84.110.56";
public int Port =53486;
void OnGUI()
{
if(Network.peerType == NetworkPeerType.Disconnected)
{
if(GUI.Button(new Rect(100,100,100,25),"Start Client."))
{
Network.Connect(IP,Port);
}
if(GUI.Button(new Rect(100,125,100,25),"Start Server."))
{
Network.InitializeServer(10,Port);
}
}
else
{
if(Network.peerType == NetworkPeerType.Client)
{
GUI.Label(new Rect(100,100,100,25),"Client.");
if(GUI.Button(new Rect(100,125,100,25),"Logout."))
{
Network.Disconnect(250);
}
}
if(Network.peerType == NetworkPeerType.Server)
{
GUI.Label(new Rect(100,100,100,25),"Server.");
GUI.Label(new Rect(100,125,100,25),"Connections: "+Network.connections.Length);
if(GUI.Button(new Rect(100,150,100,25),"Logout."))
{
Network.Disconnect(250);
}
}
}
}
}
What do you mean by nothing works? From what i can see in your code it should just display a logout button. Does it display that button or not? Also if it's on the same machine try the IP 127.0.0.1.
Try making sure that you have it running in the background, You need to have both the server and client " active " for them to communicate, go to edit , Project settings , Player then click on the resolution and presentation tab , and enable run in background.
It does not display the logout button, and in the stats panel, it does not say that anyone is connected. Also i´ve running in background on.
Try the IP: 127.0.0.1 and the Port: 35001 (IP only works if the server and client are on the same machine)