Game Development Community

Multiplayer Support

by Brandon Fogerty · in Torque Game Engine Advanced · 08/20/2009 (12:07 am) · 1 replies

I am trying to run a multiplayer game. I wrote the following function,

function onMultiPlayer()
{
   echo("TESTING!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
   Canvas.setCursor("DefaultCursor");
   
   //createServer( "SinglePlayer", expandFileName("~/data/missions/LEVEL1.mis") );
   
   createServer( "MultiPlayer", expandFileName("~/data/missions/LEVEL1.mis") );
   
   %conn = new GameConnection(ServerConnection);
   RootGroup.add(ServerConnection);
   %conn.setConnectArgs($pref::Player::Name);
   %conn.setJoinPassword($Client::Password);
   //%conn.connectLocal();
   %conn.connect("localhost:28000");
   
}

However when I execute this function, the client attempts to connect to the server and then I get an error dialog saying "Your connection to the server timed out."

Is there anything else I am missing or I need to do to run a multiplayer game?

#1
09/09/2009 (2:29 pm)
Because the game is running as a listen server you have to differentiate between local connections and remote connections.

Create a local connection with...

%result = %conn.connectLocal(); // if %result has "" then the connection was successfully

Create a remote connection with...

%conn.connect(IP:Port);
%conn.connect(1.2.3.4:28002);

Make sure to execute these two functions before a connection is established.

allowConnections(true); // remote connections are allowed (LAN or Internet)
allowConnections(false); // it is a singleplayer game, only a local connection is allowed

setNetPort(anyPortnumber); // each instance of your game has to use the same port to communicate