1AnyEvent::Handle::UDP(3Upsme)r Contributed Perl DocumentaAtniyoEnvent::Handle::UDP(3pm)
2
3
4

NAME

6       AnyEvent::Handle::UDP - client/server UDP handles for AnyEvent
7

VERSION

9       version 0.049
10

SYNOPSIS

12        my $echo_server = AnyEvent::Handle::UDP->new(
13            bind => ['0.0.0.0', 4000],
14            on_recv => sub {
15                my ($data, $ae_handle, $client_addr) = @_;
16                $ae_handle->push_send($data, $client_addr);
17            },
18        );
19

DESCRIPTION

21       This module is an abstraction around UDP sockets for use with AnyEvent.
22

ATTRIBUTES

24   on_recv
25       The callback for when a package arrives. It takes three arguments: the
26       datagram, the handle and the address the datagram was received from.
27
28   on_error
29       The callback for when an error occurs. It takes three arguments: the
30       handle, a boolean indicating the error is fatal or not, and the error
31       message.
32
33   on_drain
34       This sets the callback that is called when the send buffer becomes
35       empty. The callback takes the handle as its only argument.
36
37   autoflush
38       Always attempt to send data to the operating system immediately,
39       without waiting for the loop to indicate the filehandle is write-ready.
40
41   receive_size
42       The buffer size for the receiving in bytes. It defaults to 1500, which
43       is slightly more than the MTA on ethernet.
44
45   family
46       Sets the socket family. The default is 0, which means either IPv4 or
47       IPv6. The values 4 and 6 mean IPv4 and IPv6 respectively.
48
49   fh
50       The underlying filehandle. Note that this doesn't cooperate with the
51       "connect" and "bind" parameters.
52
53   reuse_addr
54       If true will enable quick reuse of the bound address
55
56   timeout
57   rtimeout
58   wtimeout
59       If non-zero, then these enables an "inactivity" timeout: whenever this
60       many seconds pass without a successful read or write on the underlying
61       file handle (or a call to "timeout_reset"), the on_timeout callback
62       will be invoked (and if that one is missing, a non-fatal ETIMEDOUT
63       error will be raised).
64
65       There are three variants of the timeouts that work independently of
66       each other, for both read and write (triggered when nothing was read OR
67       written), just read (triggered when nothing was read), and just write:
68       timeout, rtimeout and wtimeout, with corresponding callbacks
69       on_timeout, on_rtimeout and on_wtimeout, and reset functions
70       timeout_reset, rtimeout_reset, and wtimeout_reset.
71
72       Note that timeout processing is active even when you do not have any
73       outstanding read or write requests: If you plan to keep the connection
74       idle then you should disable the timeout temporarily or ignore the
75       timeout in the corresponding on_timeout callback, in which case
76       AnyEvent::Handle will simply restart the timeout.
77
78       Calling "clear_timeout" (or setting it to zero, which does the same)
79       disables the corresponding timeout.
80
81   on_timeout
82   on_rtimeout
83   on_wtimeout
84       The callback that's called whenever the inactivity timeout passes. If
85       you return from this callback, then the timeout will be reset as if
86       some activity had happened, so this condition is not fatal in any way.
87

METHODS

89   new
90       Create a new UDP handle. As arguments it accepts any attribute, as well
91       as these two:
92
93       ·   connect
94
95           Set the address to which datagrams are sent by default, and the
96           only address from which datagrams are received. It must be either a
97           packed sockaddr struct or an arrayref containing a hostname and a
98           portnumber.
99
100       ·   bind
101
102           The address to bind the socket to. It must be either a packed
103           sockaddr struct or an arrayref containing a hostname and a
104           portnumber.
105
106       All except "on_recv" are optional, though using either "connect" or
107       "bind" (or both) is strongly recommended unless you give it a
108       connected/bound "fh".
109
110   bind_to($address)
111       Bind to the specified addres. Note that a bound socket may be rebound
112       to another address. $address must be in the same form as the bind
113       argument to new.
114
115   connect_to($address)
116       Connect to the specified address. Note that a connected socket may be
117       reconnected to another address. $address must be in the same form as
118       the connect argument to new.
119
120   push_send($message, $to = undef, $cv = AnyEvent::CondVar->new)
121       Try to send a message. If a socket is not connected a receptient
122       address must also be given. If it is connected giving a receptient may
123       not work as expected, depending on your platform. It returns $cv, which
124       will become true when $message is sent.
125
126   timeout_reset
127   rtimeout_reset
128   wtimeout_reset
129       Reset the activity timeout, as if data was received or sent.
130
131   sockname
132       Get the local address, per "getsockname".
133
134   peername
135       Get the peer's address, per "getpeername".
136
137   destroy
138       Destroy the handle.
139

BACKWARDS COMPATIBILITY

141       This module is not backwards compatible in any way with the defunct
142       previous module of the same name by Jan Henning Thorsen.
143

AUTHOR

145       Leon Timmermans <leont@cpan.org>
146
148       This software is copyright (c) 2011 by Leon Timmermans.
149
150       This is free software; you can redistribute it and/or modify it under
151       the same terms as the Perl 5 programming language system itself.
152
153
154
155perl v5.28.0                      2018-05-16        AnyEvent::Handle::UDP(3pm)
Impressum