GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
AnyEvent::WebSocket::Connection(3) User Contributed Perl Documentation AnyEvent::WebSocket::Connection(3)

AnyEvent::WebSocket::Connection - WebSocket connection for AnyEvent

version 0.44

 # send a message through the websocket...
 $connection->send('a message');
 
 # recieve message from the websocket...
 $connection->on(each_message => sub {
   # $connection is the same connection object
   # $message isa AnyEvent::WebSocket::Message
   my($connection, $message) = @_;
   ...
 });
 
 # handle a closed connection...
 $connection->on(finish => sub {
   # $connection is the same connection object
   my($connection) = @_;
   ...
 });
 
 # close an opened connection
 # (can do this either inside or outside of
 # a callback)
 $connection->close;

(See AnyEvent::WebSocket::Client or AnyEvent::WebSocket::Server on how to create a connection)

This class represents a WebSocket connection with a remote server or a client.

If the connection object falls out of scope then the connection will be closed gracefully.

This class was created for a client to connect to a server via AnyEvent::WebSocket::Client, and was later extended to work on the server side via AnyEvent::WebSocket::Server. Once a WebSocket connection is established, the API for both client and server is identical.

The underlying AnyEvent::Handle object used for the connection. WebSocket handshake MUST be already completed using this handle. You should not use the handle directly after creating AnyEvent::WebSocket::Connection object.

Usually only useful for creating server connections, see below.

If set to true, it masks outgoing frames. The default is false.

The subprotocol returned by the server. If no subprotocol was requested, it may be "undef".

The maximum payload size for received frames. Currently defaults to whatever Protocol::WebSocket defaults to.

If provided by the other side, the code that was provided when the connection was closed.

If provided by the other side, the reason for closing the connection.

If the connection is closed due to a network error, this will hold the message.

 $connection->send($message);

Send a message to the other side. $message may either be a string (in which case a text message will be sent), or an instance of AnyEvent::WebSocket::Message.

 $connection->on(each_message => $cb);
 $connection->on(each_message => $cb);
 $connection->on(finish => $cb);

Register a callback to a particular event.

For each event $connection is the AnyEvent::WebSocket::Connection and and $message is an AnyEvent::WebSocket::Message (if available).

Returns a coderef that unregisters the callback when invoked.

 my $cancel = $connection->on( each_message => sub { ...  });
 
 # later on...
 $cancel->();

each_message

 $cb->($connection, $message, $unregister)

Called each time a message is received from the WebSocket. $unregister is a coderef that removes this callback from the active listeners when invoked.

next_message

 $cb->($connection, $message)

Called only for the next message received from the WebSocket.

parse_error

 $cb->($connection, $text_error_message)

Called if there is an error parsing a message sent from the remote end. After this callback is called, the connection will be closed. Among other possible errors, this event will trigger if a frame has a payload which is larger that "max_payload_size".

finish

 $cb->($connection, $message)

Called when the connection is terminated. If the connection is terminated due to an error, the message will be provided as the second argument. On a cleanly closed connection this will be `undef`.

 $connection->close;
 $connection->close($code);
 $connection->close($code, $reason);

Close the connection. You may optionally provide a code and a reason. See section 5.5.1 <https://tools.ietf.org/html/rfc6455#section-5.5.1> and section 7.4.1 <https://tools.ietf.org/html/rfc6455#section-7.4.1> of RFC6455.

The code is a 16-bit unsigned integer value that indicates why you close the connection. By default the code is 1005.

The reason is a character string (not an octet string) that further describes why you close the connection. By default the reason is an empty string.

Although written originally to work with AnyEvent::WebSocket::Client, this class was designed to be used for either client or server WebSocket connections. For details, contact the author and/or take a look at the source for AnyEvent::WebSocket::Client and the examples that come with Protocol::WebSocket.

  • AnyEvent::WebSocket::Client
  • AnyEvent::WebSocket::Message
  • AnyEvent::WebSocket::Server
  • AnyEvent
  • RFC 6455 The WebSocket Protocol <http://tools.ietf.org/html/rfc6455>

Author: Graham Ollis <plicease@cpan.org>

Contributors:

Toshio Ito (debug-ito, TOSHIOITO)

José Joaquín Atria (JJATRIA)

Kivanc Yazan (KYZN)

Yanick Champoux (YANICK)

This software is copyright (c) 2013 by Graham Ollis.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

2017-12-12 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.