- Home /
Unity Networking: Get information from a server
Hello, I am currently creating a game that uses networking to retrieve a list of all online servers, then has what level that server is currently on. This way, people know, when joining, what level they will load into. However, I am a bit unsure of how to go about posting the current level name and server name, and getting what level the server is on.
I have tried making this simple program to host and join the servers, but not sure how to get a list of all of the servers, nor what level it is on:
public GameObject fadeLoader;
public GameObject loadingOverlayText;
NetworkClient client_self;
bool isAtStartup;
public void exitApplication() {
Application.Quit();
}
public void submitOnlineHost() {
fadeLoader.SetActive(true);
SetupServer();
}
public void SetupServer()
{
NetworkServer.Listen(int.Parse(ipPortField.text));
isAtStartup = false;
Debug.Log("HandlerScripts: Server setup complete.");
loadingOverlayText.GetComponent<Text>().text = "Checking server integrity...";
if(NetworkServer.active) {
loadingOverlayText.GetComponent<Text>().text = " ACTIVE returned 0.";
Debug.Log("HandlerScripts:: SetupServer: ACTIVE returned FALSE.");
Debug.Log(" in bool NetworkServer.active");
return;
}
loadingOverlayText.GetComponent<Text>().text = "Uploading server information...";
// Stuck on uploading information to the server
}
// Create a client and connect to the server port
public void SetupClient()
{
client_self = new NetworkClient();
client_self.RegisterHandler(MsgType.Connect, OnConnected);
client_self.Connect("127.0.0.1", 9109);
isAtStartup = false;
}
// Create a local client and connect to the local server
public void SetupLocalClient()
{
client_self = ClientScene.ConnectLocalServer();
client_self.RegisterHandler(MsgType.Connect, OnConnected);
isAtStartup = false;
}
// client function
public void OnConnected(NetworkMessage netMsg)
{
Debug.Log("Connected to requested server");
}
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
create android multiplayer game using wifi ? 0 Answers
Not calling OnServerAddPlayer() when client connect 0 Answers
Problems with Scene Change networking Unet 0 Answers
send data from client to local server 0 Answers