1Mojo::IOLoop::Client(3)User Contributed Perl DocumentatioMnojo::IOLoop::Client(3)
2
3
4
6 Mojo::IOLoop::Client - Non-blocking TCP/IP and UNIX domain socket
7 client
8
10 use Mojo::IOLoop::Client;
11
12 # Create socket connection
13 my $client = Mojo::IOLoop::Client->new;
14 $client->on(connect => sub ($client, $handle) {...});
15 $client->on(error => sub ($client, $err) {...});
16 $client->connect(address => 'example.com', port => 80);
17
18 # Start reactor if necessary
19 $client->reactor->start unless $client->reactor->is_running;
20
22 Mojo::IOLoop::Client opens TCP/IP and UNIX domain socket connections
23 for Mojo::IOLoop.
24
26 Mojo::IOLoop::Client inherits all events from Mojo::EventEmitter and
27 can emit the following new ones.
28
29 connect
30 $client->on(connect => sub ($client, $handle) {...});
31
32 Emitted once the connection is established.
33
34 error
35 $client->on(error => sub ($client, $err) {...});
36
37 Emitted if an error occurs on the connection, fatal if unhandled.
38
40 Mojo::IOLoop::Client implements the following attributes.
41
42 reactor
43 my $reactor = $client->reactor;
44 $client = $client->reactor(Mojo::Reactor::Poll->new);
45
46 Low-level event reactor, defaults to the "reactor" attribute value of
47 the global Mojo::IOLoop singleton. Note that this attribute is
48 weakened.
49
51 Mojo::IOLoop::Client inherits all methods from Mojo::EventEmitter and
52 implements the following new ones.
53
54 can_nnr
55 my $bool = Mojo::IOLoop::Client->can_nnr;
56
57 True if Net::DNS::Native 0.15+ is installed and non-blocking name
58 resolution support enabled.
59
60 can_socks
61 my $bool = Mojo::IOLoop::Client->can_socks;
62
63 True if IO::Socket::SOCKS 0.64+ is installed and SOCKS5 support
64 enabled.
65
66 connect
67 $client->connect(address => '127.0.0.1', port => 3000);
68 $client->connect({address => '127.0.0.1', port => 3000});
69
70 Open a socket connection to a remote host. Note that non-blocking name
71 resolution depends on Net::DNS::Native (0.15+), SOCKS5 support on
72 IO::Socket::Socks (0.64), and TLS support on IO::Socket::SSL (2.009+).
73
74 These options are currently available:
75
76 address
77 address => 'mojolicious.org'
78
79 Address or host name of the peer to connect to, defaults to
80 127.0.0.1.
81
82 handle
83 handle => $handle
84
85 Use an already prepared IO::Socket::IP object.
86
87 path
88 path => '/tmp/myapp.sock'
89
90 Path of UNIX domain socket to connect to.
91
92 port
93 port => 80
94
95 Port to connect to, defaults to 80 or 443 with "tls" option.
96
97 socket_options
98 socket_options => {LocalAddr => '127.0.0.1'}
99
100 Additional options for IO::Socket::IP when opening new connections.
101
102 socks_address
103 socks_address => '127.0.0.1'
104
105 Address or host name of SOCKS5 proxy server to use for connection.
106
107 socks_pass
108 socks_pass => 'secr3t'
109
110 Password to use for SOCKS5 authentication.
111
112 socks_port
113 socks_port => 9050
114
115 Port of SOCKS5 proxy server to use for connection.
116
117 socks_user
118 socks_user => 'sri'
119
120 Username to use for SOCKS5 authentication.
121
122 timeout
123 timeout => 15
124
125 Maximum amount of time in seconds establishing connection may take
126 before getting canceled, defaults to 10.
127
128 tls
129 tls => 1
130
131 Enable TLS.
132
133 tls_ca
134 tls_ca => '/etc/tls/ca.crt'
135
136 Path to TLS certificate authority file.
137
138 tls_cert
139 tls_cert => '/etc/tls/client.crt'
140
141 Path to the TLS certificate file.
142
143 tls_key
144 tls_key => '/etc/tls/client.key'
145
146 Path to the TLS key file.
147
148 tls_options
149 tls_options => {SSL_alpn_protocols => ['foo', 'bar'], SSL_verify_mode => 0x00}
150
151 Additional options for IO::Socket::SSL.
152
154 Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
155
156
157
158perl v5.32.1 2021-02-07 Mojo::IOLoop::Client(3)