line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public License |
2
|
|
|
|
|
|
|
# or the Artistic License (the same terms as Perl itself) |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# (C) Paul Evans, 2017 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Net::Async::WebSocket::JSON::Server; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
94427
|
use strict; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
23
|
|
9
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
10
|
1
|
|
|
1
|
|
3
|
use base qw( Net::Async::WebSocket::Server ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
416
|
|
11
|
|
|
|
|
|
|
Net::Async::WebSocket::Server->VERSION( '0.11' ); # respects subclasses changing handle_class |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
53083
|
use Net::Async::WebSocket::JSON::Protocol; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
59
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
C - server WebSocket clients using JSON and C |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use IO::Async::Loop; |
24
|
|
|
|
|
|
|
use Net::Async::WebSocket::JSON::Server; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $server = Net::Async::WebSocket::JSON::Server->new( |
27
|
|
|
|
|
|
|
on_client => sub { |
28
|
|
|
|
|
|
|
my ( undef, $client ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$client->configure( |
31
|
|
|
|
|
|
|
on_json => sub { |
32
|
|
|
|
|
|
|
my ( $self, $frame ) = @_; |
33
|
|
|
|
|
|
|
$self->send_json( $frame ); |
34
|
|
|
|
|
|
|
}, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $loop = IO::Async::Loop->new; |
40
|
|
|
|
|
|
|
$loop->add( $server ); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$server->listen( |
43
|
|
|
|
|
|
|
service => 3000, |
44
|
|
|
|
|
|
|
)->get; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$loop->run; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 DESCRIPTION |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
This subclass of L provides conveniences for |
51
|
|
|
|
|
|
|
using JSON-encoded data sent over text frames. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
It should be used identically to C, except that |
54
|
|
|
|
|
|
|
connected client instances will be instances of |
55
|
|
|
|
|
|
|
L, and have the new C method |
56
|
|
|
|
|
|
|
and C event available. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub new |
61
|
|
|
|
|
|
|
{ |
62
|
1
|
|
|
1
|
1
|
3777
|
my $class = shift; |
63
|
1
|
|
|
|
|
10
|
return $class->SUPER::new( |
64
|
|
|
|
|
|
|
handle_class => "Net::Async::WebSocket::JSON::Protocol", |
65
|
|
|
|
|
|
|
@_, |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 AUTHOR |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Paul Evans |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
0x55AA; |