1Mojo::IOLoop::Client(3)User Contributed Perl DocumentatioMnojo::IOLoop::Client(3)
2
3
4

NAME

6       Mojo::IOLoop::Client - Non-blocking TCP/IP and UNIX domain socket
7       client
8

SYNOPSIS

10         use Mojo::IOLoop::Client;
11
12         # Create socket connection
13         my $client = Mojo::IOLoop::Client->new;
14         $client->on(connect => sub {
15           my ($client, $handle) = @_;
16           ...
17         });
18         $client->on(error => sub {
19           my ($client, $err) = @_;
20           ...
21         });
22         $client->connect(address => 'example.com', port => 80);
23
24         # Start reactor if necessary
25         $client->reactor->start unless $client->reactor->is_running;
26

DESCRIPTION

28       Mojo::IOLoop::Client opens TCP/IP and UNIX domain socket connections
29       for Mojo::IOLoop.
30

EVENTS

32       Mojo::IOLoop::Client inherits all events from Mojo::EventEmitter and
33       can emit the following new ones.
34
35   connect
36         $client->on(connect => sub {
37           my ($client, $handle) = @_;
38           ...
39         });
40
41       Emitted once the connection is established.
42
43   error
44         $client->on(error => sub {
45           my ($client, $err) = @_;
46           ...
47         });
48
49       Emitted if an error occurs on the connection, fatal if unhandled.
50

ATTRIBUTES

52       Mojo::IOLoop::Client implements the following attributes.
53
54   reactor
55         my $reactor = $client->reactor;
56         $client     = $client->reactor(Mojo::Reactor::Poll->new);
57
58       Low-level event reactor, defaults to the "reactor" attribute value of
59       the global Mojo::IOLoop singleton. Note that this attribute is
60       weakened.
61

METHODS

63       Mojo::IOLoop::Client inherits all methods from Mojo::EventEmitter and
64       implements the following new ones.
65
66   can_nnr
67         my $bool = Mojo::IOLoop::Client->can_nnr;
68
69       True if Net::DNS::Native 0.15+ is installed and non-blocking name
70       resolution support enabled.
71
72   can_socks
73         my $bool = Mojo::IOLoop::Client->can_socks;
74
75       True if IO::Socket::SOCKS 0.64+ is installed and SOCKS5 support
76       enabled.
77
78   connect
79         $client->connect(address => '127.0.0.1', port => 3000);
80         $client->connect({address => '127.0.0.1', port => 3000});
81
82       Open a socket connection to a remote host. Note that non-blocking name
83       resolution depends on Net::DNS::Native (0.15+), SOCKS5 support on
84       IO::Socket::Socks (0.64), and TLS support on IO::Socket::SSL (2.009+).
85
86       These options are currently available:
87
88       address
89           address => 'mojolicious.org'
90
91         Address or host name of the peer to connect to, defaults to
92         127.0.0.1.
93
94       handle
95           handle => $handle
96
97         Use an already prepared IO::Socket::IP object.
98
99       local_address
100           local_address => '127.0.0.1'
101
102         Local address to bind to.
103
104       path
105           path => '/tmp/myapp.sock'
106
107         Path of UNIX domain socket to connect to.
108
109       port
110           port => 80
111
112         Port to connect to, defaults to 80 or 443 with "tls" option.
113
114       socks_address
115           socks_address => '127.0.0.1'
116
117         Address or host name of SOCKS5 proxy server to use for connection.
118
119       socks_pass
120           socks_pass => 'secr3t'
121
122         Password to use for SOCKS5 authentication.
123
124       socks_port
125           socks_port => 9050
126
127         Port of SOCKS5 proxy server to use for connection.
128
129       socks_user
130           socks_user => 'sri'
131
132         Username to use for SOCKS5 authentication.
133
134       timeout
135           timeout => 15
136
137         Maximum amount of time in seconds establishing connection may take
138         before getting canceled, defaults to 10.
139
140       tls
141           tls => 1
142
143         Enable TLS.
144
145       tls_ca
146           tls_ca => '/etc/tls/ca.crt'
147
148         Path to TLS certificate authority file.
149
150       tls_cert
151           tls_cert => '/etc/tls/client.crt'
152
153         Path to the TLS certificate file.
154
155       tls_key
156           tls_key => '/etc/tls/client.key'
157
158         Path to the TLS key file.
159
160       tls_protocols
161           tls_protocols => ['foo', 'bar']
162
163         ALPN protocols to negotiate.
164
165       tls_verify
166           tls_verify => 0x00
167
168         TLS verification mode.
169

SEE ALSO

171       Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
172
173
174
175perl v5.28.0                      2018-10-15           Mojo::IOLoop::Client(3)
Impressum