It looks easy but I cannot figure out why I cannot connect to my server in local.
Simple Server Code:
void Start() {
if (NetworkServer.Listen(15937)) {
Debug.Log("Server Created!");
NetworkServer.RegisterHandler(MsgType.Connect, OnConnected);
} else {
Debug.Log("Failed To Create Server!");
}
}
void OnConnected(NetworkMessage netMsg) {
Debug.Log("Client connected");
}
Simple Client Code:
void Start () {
client = new NetworkClient();
client.Connect("127.0.0.1", 15937);
}
void Update () {
if (client.isConnected) {
Debug.Log("Connected to server!");
} else {
Debug.Log("Failed to Connected to server!");
}
}
PS: I get a message saying :
NetworkManager detected a script reload in the editor. This has caused the network to be shut down.
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
I am not sure if it causes the problem or not. Can someone lead me to the solution?