- Home /
Question by
Javieror · Jan 20, 2014 at 03:23 PM ·
networknewbienot-workingnetwork.connect
Network.Connect not working - newbie question
Hello,
I am trying to do my first network connection, I followed a very easy tutorial (https://www.youtube.com/watch?v=jjOe5dNOI34&list=PLm1w78-UUlMJMSYbl3JrBmtksTGqzcOVo)
and it did not work... then I allowed ports in Windows firewall (both, one for TCP and another one for UDP) and I allowed Unity Editor exception, but still don´t connect...
I built and run and then I tried to connect... it is like if the button is not working. I know that I created the server because after creating when I try to create again this message comes: Failed to initialize network interface. Is the listen port already in use?
I suppose there is something I am missing because of my newbie knowledges. ;-)
using UnityEngine;
using System.Collections;
public class network : MonoBehaviour {
public string connectionIP = "127.0.0.1";//"192.168.1.1";
public int portNumber = 3528;
private bool connected =false;
private void OnConnectedToServer(){
connected = true;
}
private void OnServerInitialized(){
connected = true;
}
private void OnDisconnectedFromServer(){
connected = false;
}
void OnGUI () {
GUI.Box (new Rect (Screen.width / 2 - 100, 20, 200, 200), "Menu");
if (!connected) {//no connectado
connectionIP = GUILayout.TextField (connectionIP);
int.TryParse(GUILayout.TextField (portNumber.ToString()), out portNumber);
if (GUILayout.Button ("Connect")){
Network.Connect (connectionIP, portNumber);
}
if (GUILayout.Button ("Host")){
Network.InitializeServer (4, portNumber, true);
Debug.Log("Server Initialised");
}
}else{
GUILayout.Label ("Conexiones: " + Network.connections.Length.ToString ());
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613130934im_/https://answers.unity.com/themes/thub/images/avi.jpg)