Sign in to follow this  
byteblock

opentnl examples

Recommended Posts

byteblock    122
Hi! Can Sombody post an working example of openTNL. I tried to compile the hello world example from the opentnl page. But it does not work. I think this examle was not updated while the opentnl versions have changed. Iam using ms visual c++ express and opentnl version 1.5.0. Compiler stops with many errors. here is the first error which will generate the others: error C2664: 'TNL::RPCEvent::RPCEvent(TNL::RPCGuaranteeType,TNL::RPCDirection)' : cannot convert parameter 1 from 'TNL::RPCDirection' to 'TNL::RPCGuaranteeType' Here is the complete example of hello world from the tnl page: include "tnl.h" #include "tnlEventConnection.h" #include "tnlNetInterface.h" #include "tnlRPC.h" #include <stdio.h> bool gQuit = false; // a flag used when the client wants to quit. using namespace TNL; // make sure we can simply use the TNL classes. class SimpleEventConnection : public EventConnection { typedef EventConnection Parent; public: // Let the network system know this is a valid network connection. TNL_DECLARE_NETCONNECTION(SimpleEventConnection); // declare the client to server message TNL_DECLARE_RPC(rpcMessageClientToServer, (const char *theMessageString)); // declare the server to client message TNL_DECLARE_RPC(rpcMessageServerToClient, (const char *theMessageString)); }; TNL_IMPLEMENT_NETCONNECTION(SimpleEventConnection, NetClassGroupGame, true); TNL_IMPLEMENT_RPC(SimpleEventConnection, rpcMessageClientToServer, (const char *messageString), NetClassGroupGameMask, RPCGuaranteedOrdered, RPCDirClientToServer, 0) { // display the message the client sent printf("Got message from client: %s\n", messageString); // send a hello world back to the client. rpcMessageServerToClient("Hello, World!"); } TNL_IMPLEMENT_RPC(SimpleEventConnection, rpcMessageServerToClient, (const char *messageString), NetClassGroupGameMask, RPCGuaranteedOrdered, RPCDirServerToClient, 0) { // display the message the server sent printf("Got a message from server: %s\n", messageString); // once the client has heard back from the server, it should quit. gQuit = true; } int main(int argc, const char **argv) { if(argc != 3) { printf("usage: simpletnltest <-server|-client> <connectAddress>"); return 1; } bool isClient = !strcmp(argv[1], "-client"); // convert the command-line address into TNL address form Address cmdAddress(argv[2]); RefPtr<NetInterface> theNetInterface; if(isClient) { Address bindAddress(IPProtocol, Address::Any, 0); // create a new NetInterface bound to any interface, any port (0) theNetInterface = new NetInterface(bindAddress); // create a new SimpleEventConnection and tell it to connect to the // server at cmdAddress. SimpleEventConnection *newConnection = new SimpleEventConnection; newConnection->connect(theNetInterface, cmdAddress); // post an RPC, to be executed when the connection is established newConnection->rpcMessageClientToServer("Hello??"); } else { // create a server net interface, bound to the cmdAddress theNetInterface = new NetInterface(cmdAddress); // notify the NetInterface that it can allow connections theNetInterface->setAllowsConnections(true); } // now just loop, processing incoming packets and sending outgoing packets // until the global quit flag is set. while(!gQuit) { theNetInterface->checkIncomingPackets(); theNetInterface->processConnections(); Platform::sleep(1); } return 0; }

Share this post


Link to post
Share on other sites
InetRoadkill    124
The example is wrong. (Don't you just hate that?)

Replace the part of the code with what's shown below:



class SimpleEventConnection : public EventConnection
{
typedef EventConnection Parent;

public:
// Let the network system know this is a valid network connection.
TNL_DECLARE_NETCONNECTION(SimpleEventConnection);

// declare the client to server message
TNL_DECLARE_RPC(rpcMessageClientToServer, (StringPtr messageString));

// declare the server to client message
TNL_DECLARE_RPC(rpcMessageServerToClient, (StringPtr theMessageString));
};



TNL_IMPLEMENT_NETCONNECTION(SimpleEventConnection, NetClassGroupGame, true);

TNL_IMPLEMENT_RPC(SimpleEventConnection, rpcMessageClientToServer, (StringPtr messageString), (messageString), NetClassGroupGameMask, RPCGuaranteedOrdered, RPCDirClientToServer, 0)
{
// display the message the client sent
printf("Got message from client: %s\n", messageString);
// send a hello world back to the client.
rpcMessageServerToClient("Hello, World!");
}

TNL_IMPLEMENT_RPC(SimpleEventConnection, rpcMessageServerToClient, (StringPtr messageString), (messageString), NetClassGroupGameMask, RPCGuaranteedOrdered, RPCDirServerToClient, 0)
{
// display the message the server sent
printf("Got a message from server: %s\n", messageString);

// once the client has heard back from the server, it should quit.
gQuit = true;
}


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this