Game Development Community

Timeout Error for Mini Chess Network Play

by Chris Jorgensen · in Torque Game Builder · 03/03/2008 (9:56 am) · 0 replies

Hey guys.

I was all ready to go Beta with mini chess (and it's newly tuned AI) when I decided that it needs network play. Alas, I'm having some problems. I keep getting connection time out errors. Here's what I do:

TGB.EXE: Acts as server and as first client --> connects fine, network commands work fine
TGB_DEBUG.EXE: Acts as second client --> most of the time gets timeout error, but has connected and received commands fine about 10% of the time.

It gets the timeout error almost immediately after I tell it to connect to the server. Any ideas what the issue might be?

Here's the code I hacked up over the weekend:

//---------------------------------------------------
//Create a server on this computer
function hostGame()
{
     echo("Hosting a game");
     createServer(true);
     $gameType = "network";
     $clientTurn = 0;
}

//Tell this client to connect to the server
function joinGame()
{ 
     echo("Joining a game");   
     connecttoserver(hostIP.getValue());
     $gameType = "network";
     $clientTurn = 1;   
}

function onConnect()
{
     echo("Yay! Connected.");
     %setup = "h h";
        
     //call this setup only after both clients have connected
     if($clientTurn == 1)
          commandToServer('SetupGame', %setup);
}

function onDisconnect()
{
     echo("Uh-oh! Connection dropped.");
}

//---------------------------------------------------

function clientSendMove(%move)
{
     commandToServer('ReceiveMove', %move);
}

function clientCmdReceiveMove(%move)
{
     echo("Move received:" SPC  %move);
     moveBox.text = %move;
     moveChessPiece(%move);
     updateChessBoard();
}

function clientCmdSetupGame(%setup)
{
     setupGame(%setup);
}

function clientCmdPlayGame(%mode)
{
     playChess(%mode);
}

//---------------------------------------------------

function serverSendOut(%function, %data)
{
     echo("Server sending out command" SPC %function SPC "with data" SPC %data);       
     %count = ClientGroup.getCount();
     for(%i = 0; %i < %count; %i++)
     {
          %recipient = ClientGroup.getObject(%i);
          commandToClient(%recipient, %function, %data);
     }
}

function serverSendMove(%move)
{
     serverSendOut('ReceiveMove',%move);
}

function serverPlayChess(%mode)
{
     serverSendOut('PlayGame',%mode);
}

function serverCmdSetupGame(%client, %setup)
{
     serverSendOut('SetupGame',%setup);
}

function serverCmdReceiveMove(%client, %move)
{       
     serverSendOut('ReceiveMove',%move);
}