Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: AnyEvent tcp_server not working

by kikuchiyo (Friar)
on Apr 03, 2020 at 22:21 UTC ( #11115017=note: print w/replies, xml ) Need Help??


in reply to AnyEvent tcp_server not working

The problem is that the  my $handle variable is private to the callback sub, and is not referenced anywhere else. So when that sub returns (immediately after push_writing your "Hello" message), it will be destroyed, and with it, your connection.

A solution is including a reference to it in one of AE::Handle's callbacks, e.g.:

on_error => sub { my ($hdl, $fatal, $msg) = @_; AE::log error => $msg; $hdl->destroy(); undef $handle; # <------ },

This way, the callback sub closes over the variable, so its reference count will be nonzero when the sub returns and thus your connection will stay alive.

Replies are listed 'Best First'.
Re^2: AnyEvent tcp_server not working
by navalned (Sexton) on Apr 03, 2020 at 22:32 UTC
    That did it. I need to go back through the manuals. I don't think I read anything that mentioned this. Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11115017]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2020-06-01 17:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (6 votes). Check out past polls.

    Notices?