Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SocketFactory Server communication between sessions

1 view
Skip to first unread message

Ty Roden

unread,
Oct 12, 2012, 9:16:15 AM10/12/12
to POE Mailing List
I am still rather new to POE, but I am charging ahead and attempting to
write a tool I need using it, but I am having an issue with communication
that I am sure someone can assist with.

I started with the code here:
http://poe.perl.org/?POE_Cookbook/TCP_Servers- the "Using Socket
Factory and ReadWrite" example at the bottom.

The server code, once modified seems to be doing most of what I need, as
clients can connect, and I can properly respond to events coming down the
line from clients. In place of the 'echo back anything the client sends
you' I am examining the data, and responding to it with what I need and all
seems to be well. The problem is that I have one client that connects that
sends me data that I need to make sure reaches the other clients so that
they can process the data arriving. I can accept and process the data from
this master client, but I cannot find how I might send the data to each
running process to in turn have their sessions react to the data arriving.
Since it is a client session just like any other that is receiving the
data, even saving down the session IDs into a hash I am having an issue
sending data across to the other sessions. Perhaps this just means that I
am going about this wrong.

Using the example code above, here is an example of how I am trying to
implement this:

sub socket_input {
my ($heap, $buf) = @_[HEAP, ARG0];
$buf =~ s/[\r\n]//gs;

#Pseudocode here to explain - not actual code.
if ($buf =~ m/matchcriteria/g) { send_to_all_clients($buf); };
}

This really just means that I need to not just process what arrives, but be
able to make other sessions process what arrives from the master client. Do
I have to build a session that is not a normal client, and bind that port
manually to make sure that it is high enough in the hierarchy to send to
all of the users using their session ID? No matter how much I have read on
the topic, I am having difficulty understanding how I might accomplish this.

The only other issue, is that I would like to be able to call a function
for each client to occasionally check local variables to make decisions on
what to do. As it sits now, the clients are purely driven by the data
arriving in the port - they examine arriving data, then do something. I
would like to add a function to have the clients regularly check a variable
for data to determine if they need to initiate a send to the connected
remote user.

Thank you all for any information you can provide.

-Ty Roden
0 new messages