Networking Question
by William Todd Scott · in Torque Game Engine · 04/24/2006 (10:32 pm) · 6 replies
Hi all,
I'm sure that the answer to this is somewhere on this site, but I can't seem to find it.
How do I determine if I am on the client or the server in C++ code?
I am using NetConnection::getConnectionToServer() to get the connection, but is there a way to tell if I am already on the server?
Thanks
Todd
I'm sure that the answer to this is somewhere on this site, but I can't seem to find it.
How do I determine if I am on the client or the server in C++ code?
I am using NetConnection::getConnectionToServer() to get the connection, but is there a way to tell if I am already on the server?
Thanks
Todd
#2
04/25/2006 (2:34 am)
I think that's what isLocalConnection has to do with... the server+client machine setup... not sure though... there's also the function isServerObject(), don't know if that would work in this case.
#4
04/27/2006 (10:18 am)
Also, objects have two methods: isServerObject() and isClientObject() which is a common way to determine what to do based on being "on the client" or "on the server" while processing an object class.
#5
one is "$AmServer" and one is "$AmClient".
one or both can be true.
04/27/2006 (10:27 am)
I added two script variables into the startup scripts of our setup,one is "$AmServer" and one is "$AmClient".
one or both can be true.
#6
@Stephen - Thanks. I am working on a subscriber based messaging system that can send messages between the client and the server. So, I don't have access to an object at the point where I need to check.
@Orion - Thanks for that idea, this may be something I need to do.
I think that I have expanded my understanding a little bit. Let me add the following and please correct me if my understanding is still off!
If I am running in single player mode, then I still have to play by the client/server rules. So, the "client" still works on ghosted objects and the "server" still does the simulation. However, if I have a message queue, it would be shared between the client & the server (in this case). So, unlike in a typical client/server mode where I would send the message to the server, in this case I would simply process the message and act on the server side, non-ghost, objects.
Also, Orion's solution will work nicely in finding out if I am in this dual situation, but I think the isLocalConnection() function tells me the same thing, right?
Thanks again for the help with this guys.
Todd
04/27/2006 (10:39 am)
Hey,@Stephen - Thanks. I am working on a subscriber based messaging system that can send messages between the client and the server. So, I don't have access to an object at the point where I need to check.
@Orion - Thanks for that idea, this may be something I need to do.
I think that I have expanded my understanding a little bit. Let me add the following and please correct me if my understanding is still off!
If I am running in single player mode, then I still have to play by the client/server rules. So, the "client" still works on ghosted objects and the "server" still does the simulation. However, if I have a message queue, it would be shared between the client & the server (in this case). So, unlike in a typical client/server mode where I would send the message to the server, in this case I would simply process the message and act on the server side, non-ghost, objects.
Also, Orion's solution will work nicely in finding out if I am in this dual situation, but I think the isLocalConnection() function tells me the same thing, right?
Thanks again for the help with this guys.
Todd
Torque Owner William Todd Scott
If I am running true client server I can tell if I am on the client or server because getConnectionToServer() returns NULL on the server.
But, if I am running in single player mode or hosting a game while playing on the same machine, is there a way to tell that? What does isLocalConnection() mean?
Thanks
Todd