- Home /
Network Connect to self after initializing server
Hi there, i´m currently making a multiplayer game, and i want the player to create a server and join that server immediately. As it is now, the player hosts a server, opens up another instance of the game and joins there.
Creating and joining is currently working.
//The player hosts a server after typing in the name of the server and Port he wants to use default port is 25600 if(creating = true)
{
Network.InitializeServer(8,Connection_Port,false);
}
// The player starts an extra game instance and joins, after typing in the IP and Port to connect to. Default is IP: 127.0.0.1, Port: 25600. if (Joining = true)
{
Network.Connect(Connect_To_Ip,Connection_Port);
}
But this does not work:
//The player Creates a server after choosing Servername and Portnumber. if(creating = true)
{
Network.InitializeServer(8,Connection_Port,false);
Network.Connect("127.0.0.1",Connection_Port);
}
ive got "Network.connections.Length" to show and is only counting 1 if i join with another instance. No errors occurs.
Getting this error: "The connection request to 127.0.0.1:26500 failed. Are you sure the server can be connected to?"
Answer by whydoidoit · Jul 30, 2012 at 08:26 PM
The player hosting the server is already connected to that server. You cannot connect to another game while you are a server so your second Network.Connect will either fail or shut down the server.
wait. so the hosting player is actually able to play with the connecting players then?
Answer by Gravn · Jul 30, 2012 at 10:30 PM
Now i get it. The host can play on the server himself, i just never let him, i just showed him a host admin page instead of the playing field :)
Exactly, that's how you can create a dedicated server ;)
Furthermore if you use a $$anonymous$$asterServer, take a look at the dedicatedServer property. This will only affect the playercount that is reported by the masterserver. If dedicatedServer is set to true, the server will not be count as player. The default is false, so the server is considered to be a player as well.
The documentation has a typing mistake in the description. The "false" in the last sentense should be "true" ;) The example is correct.
Answer by Gravn · Jul 30, 2012 at 08:25 PM
i just found this after some more searching: http://answers.unity3d.com/questions/141976/ports-and-networking-problem.html
Bunny83: "You can never connect to yourself with Unity's network system because you can only be server OR client. The only way is to start your game two times and let one be the server and the other a client..."
$$anonymous$$y game has players being the server all the time though. It just takes some fiddling with the instantiations and messages.
Your answer
Follow this Question
Related Questions
connect with Server(Host) 0 Answers
Network.Connect() won't connect? 0 Answers
How do you connect two existing networkviews? 1 Answer
Unhandled message 65 from local ip. 0 Answers
How to set up multiplayer? 2 Answers