Using sendRemoteCommand
by Gordon Marsh · in Torque Game Engine · 07/22/2006 (3:35 pm) · 7 replies
I'm having some problems making use of the sendRemoteCommand command. From this resource:
http://www.garagegames.com/mg/forums/result.thread.php?qt=26106
I can see the following line is added to the file in which you wish to use the command:
extern void sendRemoteCommand(NetConnection *conn, S32 argc, const char **argv);
but even with this, when I compile my file I get the following error:
error LNK2019: unresolved external symbol "void __cdecl sendRemoteCommand(class NetConnection *,int,char const * *)"...
Are there some includes I am missing or something?
Thanks, Gordon
http://www.garagegames.com/mg/forums/result.thread.php?qt=26106
I can see the following line is added to the file in which you wish to use the command:
extern void sendRemoteCommand(NetConnection *conn, S32 argc, const char **argv);
but even with this, when I compile my file I get the following error:
error LNK2019: unresolved external symbol "void __cdecl sendRemoteCommand(class NetConnection *,int,char const * *)"...
Are there some includes I am missing or something?
Thanks, Gordon
#2
NetEvents seems interesting though. Any suggestions for a good place to start learning? All I'm looking to do actually is enable clients to access/modify an array/hashtable on the server. Do you think NetEvents is suitable?
Thanks again,
Gordon
07/22/2006 (5:23 pm)
Thanks James, I tried a clean and rebuild but with no luck.NetEvents seems interesting though. Any suggestions for a good place to start learning? All I'm looking to do actually is enable clients to access/modify an array/hashtable on the server. Do you think NetEvents is suitable?
Thanks again,
Gordon
#3
Fun fact: Typically unpack and process are done in two steps so you don't block the incoming message queue.
To send a message to the Server, do something like this:
Like I said, to reply, you've already got the connection in Process. If you know the ID of the client, you can also get his connection doing something like this:
There might be a prettier way to do it, but that's the best I've seen so far.
Hope that helps!
07/22/2006 (5:46 pm)
Fortunately, there are examples of NetEvents everywhere in the forums and in the code. fx\lightning.cc has one. Basically, you define the contents of your message. Pack packages the message. Write is for recording and is usually the same as Pack. Unpack unpacks the message. Process is where the message is executed, and its arguement is the sending NetConnection which is handy in case you want to reply.Fun fact: Typically unpack and process are done in two steps so you don't block the incoming message queue.
To send a message to the Server, do something like this:
NetConnection *conn = NetConnection::getConnectionToServer(); AccountLoginEvent* pEvent = new AccountLoginEvent; dStrcpy( pEvent->accountName, argv[1]); dStrcpy( pEvent->password, argv[2]); conn->postNetEvent( pEvent);
Like I said, to reply, you've already got the connection in Process. If you know the ID of the client, you can also get his connection doing something like this:
NetConnection *conn = (NetConnection*)Sim::findObject( SimObjectId( clientID));
There might be a prettier way to do it, but that's the best I've seen so far.
Hope that helps!
#4
Thanks again, Gordon
07/22/2006 (5:59 pm)
Cheers James, really useful. I'll delve into this tomorrow - it's 2am here now!Thanks again, Gordon
#5
I have constructed a very basic NetEvent called ChatChangeEvent. I can call this fine from the client side, and can see that the variables seem OK... however by the time unpack is called on the server, the variables are junked.
I think I am missing something vital in the packing/unpacking process, but I can't see what. My code is very simple... as below:
ChatChangeEvent::ChatChangeEvent()
{
talkText = new char[maxTextLen];
clientName = new char[maxNameLen];
}
ChatChangeEvent::~ChatChangeEvent()
{
//if (talkText!=NULL) delete talkText;
//if (clientName!=NULL) delete clientName;
}
void ChatChangeEvent::pack(NetConnection* con, BitStream* stream)
{
stream->writeFlag(true);
stream->writeString(clientName, maxNameLen); //writeFloat(mStart.x, PositionalBits);
stream->writeString(talkText, maxTextLen); //writeFloat(mStart.y, PositionalBits);
stream->writeFlag( false );
}
void ChatChangeEvent::unpack(NetConnection* con, BitStream* stream)
{
stream->readString(clientName);
stream->readString(talkText);
Con::printf("1 Recieved chat message %s from %s", talkText, clientName);
}
07/24/2006 (9:51 am)
Can anyone help me with the following NetEvent problem?I have constructed a very basic NetEvent called ChatChangeEvent. I can call this fine from the client side, and can see that the variables seem OK... however by the time unpack is called on the server, the variables are junked.
I think I am missing something vital in the packing/unpacking process, but I can't see what. My code is very simple... as below:
ChatChangeEvent::ChatChangeEvent()
{
talkText = new char[maxTextLen];
clientName = new char[maxNameLen];
}
ChatChangeEvent::~ChatChangeEvent()
{
//if (talkText!=NULL) delete talkText;
//if (clientName!=NULL) delete clientName;
}
void ChatChangeEvent::pack(NetConnection* con, BitStream* stream)
{
stream->writeFlag(true);
stream->writeString(clientName, maxNameLen); //writeFloat(mStart.x, PositionalBits);
stream->writeString(talkText, maxTextLen); //writeFloat(mStart.y, PositionalBits);
stream->writeFlag( false );
}
void ChatChangeEvent::unpack(NetConnection* con, BitStream* stream)
{
stream->readString(clientName);
stream->readString(talkText);
Con::printf("1 Recieved chat message %s from %s", talkText, clientName);
}
#6
07/24/2006 (10:45 am)
You aren't reading the flags in the unpack method.
#7
07/24/2006 (11:32 am)
Thanks, that did the trick!
Torque 3D Owner James Spellman
In my case, I was looking to simplify communications. I started with Client Exe to Client Script to Server Script to Server Exe (and back again). I used sendRemoteCommand to go from Client Exe to Server Script to Server Exe (and back again). Then I learned how to use NetEvents so I can go straight from Exe to Exe.
Obviously, each technique has its place, but sendRemoteCommand was the hardest to get working.