- Home /
Client Cannot Connect To Host Server (Using Mirror)
In the last couple of days, I have learned a lot about the Mirror API, however, networks are new to me. My goal is to create a simple p2p [Player To Player] network server. (I know that this type of network isn't great for many reasons, but I just want to create something free and simple.)
I wanted to centralize the p2p into one script so I can apply this script to other projects in the future without cluttering and complicating everything when transferred, but that may change. Thus, the script is Client and Host/Client.
public class PlayerToPlayerScript : NetworkManager{
/*These Methods Are The Only Ones Doing Some Network Manipulation*/
public void Host() {
/*UI Interactions*/
uiTrack.Add(uiPanels[2]);
uiTrack[posIndex].SetActive(false);
posIndex++;
uiTrack[posIndex].SetActive(true);
/*Creating A Server Hosted By This User*/
NetworkManager.singleton.StartHost();
Debug.Log("Host IP: " + GetLocalIPAddress() +
" Is Active?: " + NetworkManager.singleton.isNetworkActive);
Text info = uiTrack[posIndex].gameObject.transform.GetChild(0).gameObject.GetComponent<Text>();//getting Text UI
serverInfo = "IP: " + GetLocalIPAddress() + "\nPlayers:\n" + playerName;//Updating Server Information variable
info.text = serverInfo;//Change Text On Client (Eventually I Will Also Do It To The Server)
/**
* THIS IS WHERE CREATE A ROOM
* ALSO UPDATE THE TEXT
* **/
}
public void ValidateRoomCode() {
//Note: Code Mean IP Address
/*Retreving User Input*/
InputField codeInput = uiTrack[posIndex].gameObject.transform.GetChild(0).gameObject.GetComponent<InputField>();
string code = codeInput.text;
/*Attempt To Connect to Client*/
NetworkManager.singleton.networkAddress = code;
//NetworkClient.Connect(code);
NetworkManager.singleton.StartClient();
/**CHECK THAT THE CODE IS CORRECT**/
if (NetworkClient.isConnected){
uiTrack.Add(uiPanels[4]);
uiTrack[posIndex].SetActive(false);
posIndex++;
uiTrack[posIndex].SetActive(true);
}
else
{
Debug.Log("CLIENT CANNOT CONNECT OR COULDN'T BE CONNECTED");
}
}
}
Thanks In Advance For Anyone's Help :)
Your answer
Follow this Question
Related Questions
Unity as server side? 0 Answers
Networking: Standalone Simulation Server 0 Answers
Unity dedicated server for validating data and handling data from many clients 2 Answers
My network server doesn't work. 0 Answers