Client to client messaging
by Killer7 · in Torque Game Engine · 08/23/2006 (5:09 am) · 2 replies
Hello,
I am new to TNL. I was interested in finding out whether there is an in-built mechanism in the EventConnection or NetInterface classes through which a client can identify specific clients and send them messages. Or should I make some private member (like ID or name) in the class which is a subclass of EventConnection (or the other ones I use: NetInterface, NetEvent).
Of course the server must let a client know the names/IDs of all existing other clients, this is something I have yet to do.
Currently, I just iterate through a loop (using the conn->getInterface()->getConnectionList() attained from the connection object - "conn" - I have on the server, which is of type "SimpleEventConnection", derived from EventConnection). I send all messages received on the server one by one to all existing clients. But I'd like to have the client being able to send messages to specific clients (just as a chat client does).
So what would I have to do at the time of instantiation of a client-connection (on the client or server side) and then at the time of sending the message from the client.
Thanks in advance.
I am using NetEvent to post the message. Here is the process function:
//----------------------------------------------------------------------------------//
void SimpleMessageEvent::process(EventConnection *conn)
{
printf("SimpleMessageEvent received:%s", msg);
TNL::Vector con_list = conn->getInterface()->getConnectionList();
printf("Server has %d clients!", con_list.size());
for(int i = 0; i < con_list.size(); i++){
SimpleEventConnection *con = (SimpleEventConnection *)con_list[i];
con->rpcMessageServerToClient(msg);
}
}
//----------------------------------------------------------------------------------//
I am new to TNL. I was interested in finding out whether there is an in-built mechanism in the EventConnection or NetInterface classes through which a client can identify specific clients and send them messages. Or should I make some private member (like ID or name) in the class which is a subclass of EventConnection (or the other ones I use: NetInterface, NetEvent).
Of course the server must let a client know the names/IDs of all existing other clients, this is something I have yet to do.
Currently, I just iterate through a loop (using the conn->getInterface()->getConnectionList() attained from the connection object - "conn" - I have on the server, which is of type "SimpleEventConnection", derived from EventConnection). I send all messages received on the server one by one to all existing clients. But I'd like to have the client being able to send messages to specific clients (just as a chat client does).
So what would I have to do at the time of instantiation of a client-connection (on the client or server side) and then at the time of sending the message from the client.
Thanks in advance.
I am using NetEvent to post the message. Here is the process function:
//----------------------------------------------------------------------------------//
void SimpleMessageEvent::process(EventConnection *conn)
{
printf("SimpleMessageEvent received:%s", msg);
TNL::Vector
printf("Server has %d clients!", con_list.size());
for(int i = 0; i < con_list.size(); i++){
SimpleEventConnection *con = (SimpleEventConnection *)con_list[i];
con->rpcMessageServerToClient(msg);
}
}
//----------------------------------------------------------------------------------//
Torque Owner Shyam "Doggan" Guthikonda
Let''s use the example you mentioned: Client X wants to send a message to Client Y. Only client Y should receive the message. There are 3 NetInterfaces here: client X, client Y, and the server. Each has a unique id. Client X posts an event to the server. Client X needs to pack his unique ID and the message to be transmitted into the event packet. The event is received by the server. In the [i]process[/u] method, you can simply call conn->getNetAddressString(). This gives you the ip address of the client on this connection, which is also the unique ID. If this ip matches the unique ID packed with the event, you know this is the correct client, so you can send the message away.