Net::Async::WebSocket::Client - connect to a WebSocket server using IO::Async
Net::Async::WebSocket::Client
IO::Async
use IO::Async::Loop; use Net::Async::WebSocket::Client; my $client = Net::Async::WebSocket::Client->new( on_frame => sub { my ( $self, $frame ) = @_; print $frame; }, ); my $loop = IO::Async::Loop->new; $loop->add( $client ); $client->connect( host => $HOST, service => $PORT, url => "ws://$HOST:$PORT/", on_connected => sub { $client->send_frame( "Hello, world!\n" ); }, on_connect_error => sub { die "Cannot connect - $_[-1]" }, on_resolve_error => sub { die "Cannot resolve - $_[-1]" }, ); $loop->loop_forever;
This subclass of Net::Async::WebSocket::Protocol connects to a WebSocket server to establish a WebSocket connection for passing frames.
Connect to a WebSocket server. Takes the following named parameters:
URL to provide to WebSocket handshake
When not returning a Future, the following additional parameters provide continuations:
Future
CODE reference to invoke when the handshaking is complete.
Sets the read and write handles to the IO reference given, then performs the initial handshake using the parameters given. These are as for connect.
connect
Paul Evans <leonerd@leonerd.org.uk>
To install Net::Async::WebSocket, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Async::WebSocket
CPAN shell
perl -MCPAN -e shell install Net::Async::WebSocket
For more information on module installation, please visit the detailed CPAN module installation guide.