- Home /
A Couple Questions on Networking
Im working on the networking part of my game and i have some questions about it...
Ive been using the Unity C# Scripting Reference in order to do this and I was wondering why i was getting this, error... Its more of a warning but listed as an error.
The connection request to 127.0.0.1:25001 failed. Are you sure the server can be connected to?
I have my scripts basically set up like this.
This is the button (Which is in the OnGUI but i dont want to include everything)
if(GUI.Button(new Rect((Screen.width / 2), (Screen.height / 2) + 245, 200, 25), "Start Server!")){
if((CanContinue == 0) && (MyServerDifficulty >= 1)) {
if(isPasswordProtected == true) {
Network.incomingPassword = MyServerPassword;
bool useNat = !Network.HavePublicAddress();
Network.InitializeServer(32, listenPort, useNat);
}
else {
bool useNat = !Network.HavePublicAddress();
Network.InitializeServer(32, listenPort, useNat);
}
}
else if((CanContinue != 1) && (MyServerDifficulty >= 1))
{
ServerError = "You Need To Fill In a Server Name!";
}
else if((CanContinue == 1) && (MyServerDifficulty == 0)){
ServerError = "You Need To Choose Your Servers Difficulty!";
}
else
{
ServerError = "You Need to Have a Server Name and Pick Your Servers Difficulty!";
}
}
And then i have the Server Initialization Function
void OnServerInitialized() {
Debug.Log("Server initialized and ready");
Debug.Log("==> GUID is " + Network.player.guid + ". Use this on clients to connect with NAT punchthrough.");
Debug.Log("==> Local IP/port is " + Network.player.ipAddress + "/" + Network.player.port + ". Use this on clients to connect directly.");
Network.Connect(remoteIP, remotePort);
}
Any Ideas on whats wrong? It clearly Initializes the server because i get all of those logs in the console but i cant seem to figure out whats causing it to not let me to connect.
2nd Question, Using this would the player be able to host there own server no problem or would it be LAN? And would they be able to Port Forward to get it others to connect?
3rd Question, Would i have to set up some sort of databases to get this to display all the servers in game...
i.e. How valve does there multiplayer server list for games like tf2, css, and gmod, Ive ran a tf2 and gmod server before and once i get it port forwarded and everything it displays my server in there multiplayer server list without me having to do any submission.
Would this require to have a database of some sort set up and when they start server it submits there server with there server name, max connections, etc... into the database and then on the in-game end have it display in an array or something?
4th Question, Once a server is initialized can it continue to work throughout multiple scenes without having to start up another server after each scene/level?
Once again like a valves game, i.e. lf4, how once you finish the first level and enter the safe room, it goes to a new level.
With old networking setups, which were done poorly in the first place, once i got a connection established between me and a friend, once we would go to the next scene we would both be "kicked" from the server, even the host would be kicked.
I dont have those old networking scripts but would i need to do something for that not to happen in my new script?
Sorry for the question being long, Thanks for all help in advance