Net-WebSocket
view release on metacpan or search on metacpan
demo/123_server.pl view on Meta::CPAN
use Net::WebSocket::Endpoint::Server ();
use Net::WebSocket::Parser ();
use Net::WebSocket::Streamer::Server ();
my $host_port = $ARGV[0] || die "Need host:port or port!\n";
if (index($host_port, ':') == -1) {
substr( $host_port, 0, 0 ) = '127.0.0.1:';
}
my ($host, $port) = split m<:>, $host_port;
my $server = IO::Socket::INET->new(
LocalHost => $host,
LocalPort => $port,
ReuseAddr => 1,
Listen => 2,
);
#This is a âlazyâ example. A more robust, production-level
#solution would not need to fork() unless there were privilege
demo/echo_server.pl view on Meta::CPAN
use Net::WebSocket::PMCE::deflate::Server ();
$SIG{'PIPE'} = 'IGNORE';
my $host_port = $ARGV[0] || die "Need host:port or port!\n";
if (index($host_port, ':') == -1) {
substr( $host_port, 0, 0 ) = '127.0.0.1:';
}
my ($host, $port) = split m<:>, $host_port;
my $server = IO::Socket::INET->new(
LocalHost => $host,
LocalPort => $port,
ReuseAddr => 1,
Listen => 2,
);
#This is a âlazyâ example. A more robust, production-level
#solution would not need to fork() unless there were privilege
demo/shell_server.pl view on Meta::CPAN
#for setsid()
use POSIX ();
my $host_port = $ARGV[0] || die "Need host:port or port!\n";
if (index($host_port, ':') == -1) {
substr( $host_port, 0, 0 ) = '127.0.0.1:';
}
my ($host, $port) = split m<:>, $host_port;
#my $loop = IO::Events::Loop->new( debug => 1 );
my $loop = IO::Events::Loop->new();
my %sessions;
sub _kill_session {
my ($session) = @_;
if ( $sessions{$session} ) {
demo/wscat.pl view on Meta::CPAN
if (!$uri_scheme) {
die "Need a URI!\n";
}
if ($uri_scheme !~ m<\Awss?\z>) {
die sprintf "Invalid schema: â%sâ ($uri)\n", $uri_scheme;
}
my $inet;
my ($host, $port) = split m<:>, $uri_authority;
if ($uri_scheme eq 'ws') {
my $iaddr = Socket::inet_aton($host);
$port ||= 80;
my $paddr = Socket::pack_sockaddr_in( $port, $iaddr );
socket( $inet, Socket::PF_INET(), Socket::SOCK_STREAM(), 0 );
connect( $inet, $paddr );
}
demo/wscat_the_hard_way.pl view on Meta::CPAN
if (!$uri_scheme) {
die "Need a URI!\n";
}
if ($uri_scheme !~ m<\Awss?\z>) {
die sprintf "Invalid schema: â%sâ ($uri)\n", $uri_scheme;
}
my $inet;
my ($host, $port) = split m<:>, $uri_authority;
if ($uri_scheme eq 'ws') {
my $iaddr = Socket::inet_aton($host);
$port ||= 80;
my $paddr = Socket::pack_sockaddr_in( $port, $iaddr );
socket( $inet, Socket::PF_INET(), Socket::SOCK_STREAM(), 0 );
connect( $inet, $paddr );
}
lib/Net/WebSocket/HTTP.pm view on Meta::CPAN
#but â#1tokenâ doesnât appear in the HTTP RFC.
sub split_tokens {
my ($value) = @_;
Call::Context::must_be_list();
$value =~ s<\A[ \t]+><>;
$value =~ s<[ \t]+\z><>;
my @tokens;
for my $p ( split m<[ \t]*,[ \t]*>, $value ) {
if ($p =~ tr~()<>@,;:\\"/[]?={} \t~~) {
die Net::WebSocket::X->create('BadToken', $p);
}
push @tokens, $p;
}
return @tokens;
}
lib/Net/WebSocket/Handshake/Client.pm view on Meta::CPAN
}
if (!$opts{'uri_schema'} || !grep { $_ eq $opts{'uri_schema'} } SCHEMAS()) {
die Net::WebSocket::X->create('BadArg', uri => $opts{'uri'});
}
if (!length $opts{'uri_auth'}) {
die Net::WebSocket::X->create('BadArg', uri => $opts{'uri'});
}
@opts{ 'uri_host', 'uri_port' } = split m<:>, $opts{'uri_auth'};
$opts{'key'} ||= _create_key();
return $class->SUPER::new(%opts);
}
=head2 I<OBJ>->valid_status_or_die( CODE, REASON )
Throws an exception if the given CODE isnât the HTTP status code (101)
that WebSocket requires in response to all requests. (REASON is included
( run in 1.540 second using v1.01-cache-2.11-cpan-71847e10f99 )