#!/usr/bin/perl # Websocket Broadcast Server use Net::WebSocket::Server; use POSIX qw(strftime); my $port = 443; $| = 1; print "Listen on $port\n"; Net::WebSocket::Server->new( listen => $port, on_connect => sub { my ($serv, $conn) = @_; $conn->on( handshake => sub { my ($conn, $handshake) = @_; print "handshake: @_\n"; }, utf8 => sub { my ($conn, $msg) = @_; $_->send_utf8(strftime("%X", localtime(time))."\0".$msg) for $conn->server->connections; print "utf8: $msg\n"; }, binary => sub { my ($conn, $msg) = @_; $_->send_binary($msg) for $conn->server->connections; print "binary: $msg\n"; }, ); }, )->start;