Game Development Community

Changes to HelloWorld Tutorial for 1.5

by CrimsonShadow · in Torque Game Engine · 07/08/2005 (11:52 pm) · 2 replies

I was looking for a network library for a game and thought I'd give TNL a try so I downloaded it and built it with VC7.1 and everything worked fine. When I tried to compile/run the HelloWorld tutorial however I ran into a couple of problems. I got them sorted away now though so I figured I'd just post the changes I made to get it to work and maybe someone can update the docs. At the very least maybe newbies to the library (like myself ;) ) will be able to get it working easier.

In the declaration of the of the RPCs you need to change the 'const char*' arguments to be 'StringPtr' because 'const char*' is no longer supported for 1.5.

From
// declare the client to server message
    TNL_DECLARE_RPC(rpcMessageClientToServer, ([b]const char*[/b]theMessageString));

    // declare the server to client message
    TNL_DECLARE_RPC(rpcMessageServerToClient, ([b]const char*[/b]theMessageString));

To
// declare the client to server message
    TNL_DECLARE_RPC(rpcMessageClientToServer, ([b]StringPtr [/b]theMessageString));

    // declare the server to client message
    TNL_DECLARE_RPC(rpcMessageServerToClient, ([b]StringPtr[/b] theMessageString));

This same change must be made to the implementations but now the macros also take the name of the arguments in as well so you have to add this paramter after the parameters themselves.

From
TNL_IMPLEMENT_RPC(SimpleEventConnection, rpcMessageClientToServer, 
([b]const char*[/b]messageString),
NetClassGroupGameMask, RPCGuaranteedOrdered, RPCDirClientToServer, 0)

// ... implementation omitted.

TNL_IMPLEMENT_RPC(SimpleEventConnection, rpcMessageServerToClient, 
([b]const char*[/b]messageString),
NetClassGroupGameMask, RPCGuaranteedOrdered, RPCDirServerToClient, 0)

To
TNL_IMPLEMENT_RPC(SimpleEventConnection, rpcMessageClientToServer, 
([b]StringPtr [/b]messageString), [b](messageString),[/b]
NetClassGroupGameMask, RPCGuaranteedOrdered, RPCDirClientToServer, 0)

// ... implementation omitted.

TNL_IMPLEMENT_RPC(SimpleEventConnection, rpcMessageServerToClient, 
([b]StringPtr [/b]messageString), [b](messageString),[/b]
NetClassGroupGameMask, RPCGuaranteedOrdered, RPCDirServerToClient, 0)

Finally in the printf calls in the implementations of the RPCs because we're using StringPtr instead of 'const char*' we need to get the c-string from the StringPtr.

From
{
    // 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!");
}

// ... macro omitted.

{
    // 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;
}

To
{
    // display the message the client sent
    printf("Got message from client: %s\n", messageString[b].getString()[/b]);
    // send a hello world back to the client.
    rpcMessageServerToClient("Hello, World!");
}

// ... macro omitted.

{
    // display the message the server sent
    printf("Got a message from server: %s\n", messageString[b].getString()[/b]);

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

NOTE: It says it in the tutorial but just to make sure.... :) You NEED to have RTTI (run time type information) turned on for this to work. I don't know how long I spent trying to figure out why the server crashed after a client connected before I realized this was off...

Have fun,
-CrimsonShadow

About the author

Recent Threads


#1
10/23/2007 (11:15 pm)
I can run this sample app as a client exactly 2 times and then the server stops responding. Thoughts?

Client console:

C:\src\tnltest\Debug>tnltest.exe -client 127.0.0.1:28000
Got a message from server: Hello, World!

C:\src\tnltest\Debug>tnltest.exe -client 127.0.0.1:28000
Got a message from server: Hello, World!

C:\src\tnltest\Debug>tnltest.exe -client 127.0.0.1:28000


Server console:

C:\src\tnltest\Debug>tnltest.exe -server 127.0.0.1:28000
Got message from client: Hello??
Got message from client: Hello??
#2
08/07/2008 (1:21 am)
Hi all,

Sorry for digging out this old thread but I'm an opentnl newbie and I face the exact same issue. Have you find the reason for it ?

Thanks in advance.

Edit: More details:
I'm on ubuntu 8.04 so gcc is 4.2.3. It seems the client hang endlessly. if you stop the client and run it again from the same shell, same behavior. But if you open another shell, it runs fine twice again then hang as well.

If I run server and client from gdb or valgrind, it runs fine more than twice, eventually hang for a while but still give a result, but still happens to hang "endlessly"

valgrind pointed out several things on both server and client side, all related to calls to TNL::Socket::sendto(...).
Here is an example :
==15784== 1 errors in context 1 of 2:
==15784== Syscall param socketcall.sendto(msg) points to uninitialised byte(s)
==15784== at 0x40007F2: (within /lib/ld-2.7.so)
==15784== by 0x805ADB1: TNL::NetInterface::sendto(TNL::Address const&, TNL::BitStream*) (netInterface.cpp:100)
==15784== by 0x805436B: TNL::NetConnection::sendPacket(TNL::BitStream*) (netConnection.cpp:732)
==15784== by 0x80547D0: TNL::NetConnection::checkPacketSend(bool, unsigned) (netConnection.cpp:689)
==15784== by 0x805AED4: TNL::NetInterface::processConnections() (netInterface.cpp:321)
==15784== by 0x8049BCD: main (main.cpp:90)
==15784== Address 0xbee81c63 is on thread 1's stack

I'll keep digging into this but any helps welcome ;)