Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: AnyEvent tcp_server not working

by kikuchiyo (Hermit)
on Apr 03, 2020 at 22:21 UTC ( [id://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 (Beadle) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11115017]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-03-28 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found