- Home /
Network connect reconnection
hi, I would make sure that the client continuously try to connect to the server until it succeeds. This code works, but only if the ControlConnected() is called in the Start() function. in the Update() does not work. I also tried to use a one-second interval between connection attempts without success.
var ip="192.168.1.1";
var Host="Yes";
var connected=false;
function Start(){
Server();
ControlConnected();
}
function Update() {
//ControlConnected();
}
function ControlConnected(){
if (connected==false) Network.Connect(ip, 5300);
}
function Server()
{
if (Host=="Yes") Network.InitializeServer(10, 5300, false);
}
function OnConnectedToServer() {
connected=true;
}
Answer by leonida · Feb 26, 2013 at 10:22 AM
solved! instead of using update I used a very long timeout.
var ip="192.168.1.1";
var Host="Yes";
var seconds=60;
var connected=false;
function Start(){
Server();
ControlConnected();
}
function ControlConnected(){
for (i=0;i<seconds;i++){
yield WaitForSeconds(1);
if (connected==false) {
Network.Connect(ip, 5300);
}
function Server()
{
if (Host=="Yes") Network.InitializeServer(10, 5300, false);
}
function OnConnectedToServer() {
connected=true;
}
Your answer
Follow this Question
Related Questions
what protocol to use for open connection in unity3d? 1 Answer
OnConnectedToServer called multiple times 1 Answer
Receiving NAT punchthrough attempt from target 684547167205435679 failed.. 1 Answer
Can't Establish connection using NetworkTransport 0 Answers
Client connects to server, but Network.peerType returns Disconnected until next click 2 Answers