.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Mojo::IOLoop::Client 3pm" .TH Mojo::IOLoop::Client 3pm 2024-05-15 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Mojo::IOLoop::Client \- Non\-blocking TCP/IP and UNIX domain socket client .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Mojo::IOLoop::Client; \& \& # Create socket connection \& my $client = Mojo::IOLoop::Client\->new; \& $client\->on(connect => sub ($client, $handle) {...}); \& $client\->on(error => sub ($client, $err) {...}); \& $client\->connect(address => \*(Aqexample.com\*(Aq, port => 80); \& \& # Start reactor if necessary \& $client\->reactor\->start unless $client\->reactor\->is_running; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Mojo::IOLoop::Client opens TCP/IP and UNIX domain socket connections for Mojo::IOLoop. .SH EVENTS .IX Header "EVENTS" Mojo::IOLoop::Client inherits all events from Mojo::EventEmitter and can emit the following new ones. .SS connect .IX Subsection "connect" .Vb 1 \& $client\->on(connect => sub ($client, $handle) {...}); .Ve .PP Emitted once the connection is established. .SS error .IX Subsection "error" .Vb 1 \& $client\->on(error => sub ($client, $err) {...}); .Ve .PP Emitted if an error occurs on the connection, fatal if unhandled. .SH ATTRIBUTES .IX Header "ATTRIBUTES" Mojo::IOLoop::Client implements the following attributes. .SS reactor .IX Subsection "reactor" .Vb 2 \& my $reactor = $client\->reactor; \& $client = $client\->reactor(Mojo::Reactor::Poll\->new); .Ve .PP Low-level event reactor, defaults to the \f(CW\*(C`reactor\*(C'\fR attribute value of the global Mojo::IOLoop singleton. Note that this attribute is weakened. .SH METHODS .IX Header "METHODS" Mojo::IOLoop::Client inherits all methods from Mojo::EventEmitter and implements the following new ones. .SS can_nnr .IX Subsection "can_nnr" .Vb 1 \& my $bool = Mojo::IOLoop::Client\->can_nnr; .Ve .PP True if Net::DNS::Native 0.15+ is installed and non-blocking name resolution support enabled. .SS can_socks .IX Subsection "can_socks" .Vb 1 \& my $bool = Mojo::IOLoop::Client\->can_socks; .Ve .PP True if IO::Socket::SOCKS 0.64+ is installed and SOCKS5 support enabled. .SS connect .IX Subsection "connect" .Vb 2 \& $client\->connect(address => \*(Aq127.0.0.1\*(Aq, port => 3000); \& $client\->connect({address => \*(Aq127.0.0.1\*(Aq, port => 3000}); .Ve .PP Open a socket connection to a remote host. Note that non-blocking name resolution depends on Net::DNS::Native (0.15+), SOCKS5 support on IO::Socket::Socks (0.64), and TLS support on IO::Socket::SSL (2.009+). .PP These options are currently available: .IP address 2 .IX Item "address" .Vb 1 \& address => \*(Aqmojolicious.org\*(Aq .Ve .Sp Address or host name of the peer to connect to, defaults to \f(CW127.0.0.1\fR. .IP handle 2 .IX Item "handle" .Vb 1 \& handle => $handle .Ve .Sp Use an already prepared IO::Socket::IP object. .IP path 2 .IX Item "path" .Vb 1 \& path => \*(Aq/tmp/myapp.sock\*(Aq .Ve .Sp Path of UNIX domain socket to connect to. .IP port 2 .IX Item "port" .Vb 1 \& port => 80 .Ve .Sp Port to connect to, defaults to \f(CW80\fR or \f(CW443\fR with \f(CW\*(C`tls\*(C'\fR option. .IP socket_options 2 .IX Item "socket_options" .Vb 1 \& socket_options => {LocalAddr => \*(Aq127.0.0.1\*(Aq} .Ve .Sp Additional options for IO::Socket::IP when opening new connections. .IP socks_address 2 .IX Item "socks_address" .Vb 1 \& socks_address => \*(Aq127.0.0.1\*(Aq .Ve .Sp Address or host name of SOCKS5 proxy server to use for connection. .IP socks_pass 2 .IX Item "socks_pass" .Vb 1 \& socks_pass => \*(Aqsecr3t\*(Aq .Ve .Sp Password to use for SOCKS5 authentication. .IP socks_port 2 .IX Item "socks_port" .Vb 1 \& socks_port => 9050 .Ve .Sp Port of SOCKS5 proxy server to use for connection. .IP socks_user 2 .IX Item "socks_user" .Vb 1 \& socks_user => \*(Aqsri\*(Aq .Ve .Sp Username to use for SOCKS5 authentication. .IP timeout 2 .IX Item "timeout" .Vb 1 \& timeout => 15 .Ve .Sp Maximum amount of time in seconds establishing connection may take before getting canceled, defaults to \f(CW10\fR. .IP tls 2 .IX Item "tls" .Vb 1 \& tls => 1 .Ve .Sp Enable TLS. .IP tls_ca 2 .IX Item "tls_ca" .Vb 1 \& tls_ca => \*(Aq/etc/tls/ca.crt\*(Aq .Ve .Sp Path to TLS certificate authority file. .IP tls_cert 2 .IX Item "tls_cert" .Vb 1 \& tls_cert => \*(Aq/etc/tls/client.crt\*(Aq .Ve .Sp Path to the TLS certificate file. .IP tls_key 2 .IX Item "tls_key" .Vb 1 \& tls_key => \*(Aq/etc/tls/client.key\*(Aq .Ve .Sp Path to the TLS key file. .IP tls_options 2 .IX Item "tls_options" .Vb 1 \& tls_options => {SSL_alpn_protocols => [\*(Aqfoo\*(Aq, \*(Aqbar\*(Aq], SSL_verify_mode => 0x00} .Ve .Sp Additional options for IO::Socket::SSL. .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .