Hi there, I seem to have the same problem. I am pretty new to Perl (not new to programming). I would like to create a TCP server, so I read some stuff at the POE site and decided to use this one (POE: Cookbook - Chat Server) as a skeleton. I added a few things in order to have the sockets stuff right, before I continue developing. Here is my code:

#!/usr/bin/env perl use warnings; use strict; use POE::Kernel { loop => 'POE::XS::Loop::EPoll' }; use POE qw(Component::Server::TCP); POE::Component::Server::TCP->new( Alias => "chat_server", Port => 32080, InlineStates => {send => \&handle_send}, ClientConnected => \&client_connected, ClientError => \&client_error, ClientDisconnected => \&client_disconnected, ClientInput => \&client_input, ); $poe_kernel->run(); exit 0; my %users; sub broadcast { my ($sender, $message) = @_; foreach my $user (keys %users) { if ($user == $sender) { $poe_kernel->post($user => send => "You $message"); } else { $poe_kernel->post($user => send => "$sender $message"); } } } sub handle_send { my ($heap, $message) = @_[HEAP, ARG0]; $heap->{client}->put($message); } sub client_connected { my $session_id = $_[SESSION]->ID; $users{$session_id} = 1; broadcast($session_id, "connected."); } sub client_disconnected { my $session_id = $_[SESSION]->ID; delete $users{$session_id}; broadcast($session_id, "disconnected."); } sub client_error { my $session_id = $_[SESSION]->ID; delete $users{$session_id}; broadcast($session_id, "disconnected."); $_[KERNEL]->yield("shutdown"); } sub client_input { my ($kernel, $session, $input) = @_[KERNEL, SESSION, ARG0]; my $session_id = $session->ID; if ($input eq "/quit") { # user entered /quit $poe_kernel->post($session_id => send => "goodbye"); $kernel->yield("shutdown"); return; } elsif ($input eq "/shutdown") { # user entered /shutdown $poe_kernel->post($session_id => send => "don't do that!"); ### how to do this, shutdown the server $kernel->call('chat_server', 'shutdown'); ######################################### return; } broadcast($session_id, "said: $input"); }

I added:

When I use a telnet client to connect, the /shutdown command works, because the "don't do that!" debug message is displayed. The line $kernel->call('chat_server', 'shutdown'); might be wrong because it doesn't shutdown the server program, but there isn't an error message displayed. Can anyone please tell me which instruction to use? I tried several things, like $kernel->yield('chat_server', "shutdown"); and $poe_kernel->post('chat_server, 'shutdown');. The POE::Component::Server::TCP can't help me.


In reply to Re^2: POE - can't shutdown Component::Server::TCP from Component::Client::TCP by pacow
in thread POE - can't shutdown Component::Server::TCP from Component::Client::TCP by jsarrel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.