1AnyEvent::Handle::UDP(3Upsme)r Contributed Perl DocumentaAtniyoEnvent::Handle::UDP(3pm)
2
3
4
6 AnyEvent::Handle::UDP - client/server UDP handles for AnyEvent
7
9 version 0.050
10
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
21 This module is an abstraction around UDP sockets for use with AnyEvent.
22
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_bind
34 The callback for when the bind has been performed (this may be after
35 object construction if address lookup is involved).
36
37 on_connect
38 The callback for when the connect has been performed (this may be after
39 object construction if address lookup is involved).
40
41 on_drain
42 This sets the callback that is called when the send buffer becomes
43 empty. The callback takes the handle as its only argument.
44
45 autoflush
46 Always attempt to send data to the operating system immediately,
47 without waiting for the loop to indicate the filehandle is write-ready.
48
49 receive_size
50 The buffer size for the receiving in bytes. It defaults to 1500, which
51 is slightly more than the MTA on ethernet.
52
53 family
54 Sets the socket family. The default is 0, which means either IPv4 or
55 IPv6. The values 4 and 6 mean IPv4 and IPv6 respectively.
56
57 fh
58 The underlying filehandle. Note that this doesn't cooperate with the
59 "connect" and "bind" parameters.
60
61 reuse_addr
62 If true will enable quick reuse of the bound address
63
64 timeout
65 rtimeout
66 wtimeout
67 If non-zero, then these enables an "inactivity" timeout: whenever this
68 many seconds pass without a successful read or write on the underlying
69 file handle (or a call to "timeout_reset"), the on_timeout callback
70 will be invoked (and if that one is missing, a non-fatal ETIMEDOUT
71 error will be raised).
72
73 There are three variants of the timeouts that work independently of
74 each other, for both read and write (triggered when nothing was read OR
75 written), just read (triggered when nothing was read), and just write:
76 timeout, rtimeout and wtimeout, with corresponding callbacks
77 on_timeout, on_rtimeout and on_wtimeout, and reset functions
78 timeout_reset, rtimeout_reset, and wtimeout_reset.
79
80 Note that timeout processing is active even when you do not have any
81 outstanding read or write requests: If you plan to keep the connection
82 idle then you should disable the timeout temporarily or ignore the
83 timeout in the corresponding on_timeout callback, in which case
84 AnyEvent::Handle will simply restart the timeout.
85
86 Calling "clear_timeout" (or setting it to zero, which does the same)
87 disables the corresponding timeout.
88
89 on_timeout
90 on_rtimeout
91 on_wtimeout
92 The callback that's called whenever the inactivity timeout passes. If
93 you return from this callback, then the timeout will be reset as if
94 some activity had happened, so this condition is not fatal in any way.
95
97 new
98 Create a new UDP handle. As arguments it accepts any attribute, as well
99 as these two:
100
101 • connect
102
103 Set the address to which datagrams are sent by default, and the
104 only address from which datagrams are received. It must be either a
105 packed sockaddr struct or an arrayref containing a hostname and a
106 portnumber.
107
108 • bind
109
110 The address to bind the socket to. It must be either a packed
111 sockaddr struct or an arrayref containing a hostname and a
112 portnumber.
113
114 All except "on_recv" are optional, though using either "connect" or
115 "bind" (or both) is strongly recommended unless you give it a
116 connected/bound "fh".
117
118 bind_to($address)
119 Bind to the specified addres. Note that a bound socket may be rebound
120 to another address. $address must be in the same form as the bind
121 argument to new.
122
123 connect_to($address)
124 Connect to the specified address. Note that a connected socket may be
125 reconnected to another address. $address must be in the same form as
126 the connect argument to new.
127
128 push_send($message, $to = undef, $cv = AnyEvent::CondVar->new)
129 Try to send a message. If a socket is not connected a receptient
130 address must also be given. If it is connected giving a receptient may
131 not work as expected, depending on your platform. It returns $cv, which
132 will become true when $message is sent.
133
134 timeout_reset
135 rtimeout_reset
136 wtimeout_reset
137 Reset the activity timeout, as if data was received or sent.
138
139 sockname
140 Get the local address, per "getsockname".
141
142 peername
143 Get the peer's address, per "getpeername".
144
145 destroy
146 Destroy the handle.
147
149 This module is not backwards compatible in any way with the defunct
150 previous module of the same name by Jan Henning Thorsen.
151
153 Leon Timmermans <leont@cpan.org>
154
156 This software is copyright (c) 2011 by Leon Timmermans.
157
158 This is free software; you can redistribute it and/or modify it under
159 the same terms as the Perl 5 programming language system itself.
160
161
162
163perl v5.34.0 2021-07-22 AnyEvent::Handle::UDP(3pm)