1 2 3 4 5 6 7 8 9 10 11 12
# handshake if( my $key = $ENV{HTTP_SEC_WEBSOCKET_KEY} ){ $key .= '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'; # WTF $key = Digest::SHA::sha1($key); $key = MIME::Base64::encode_base64($key); $key =~ s{\s+}{}g; print "HTTP/1.1 101 WebSocket Protocol Handshake\n"; print "Sec-WebSocket-Accept: $key\n"; print "Connection: Upgrade, Keep-Alive \n"; print "Upgrade: WebSocket\n"; }
2023-11-06T18:17:19 rostiWie sieht denn das Perl davon aus?Ziel ist ein Chat, hier die Demoversion:
http://rolfrost.de/wschat.html
2023-11-07T09:56:36 bianca2023-11-06T18:17:19 rostiWie sieht denn das Perl davon aus?Ziel ist ein Chat, hier die Demoversion:
http://rolfrost.de/wschat.html
var ws = new WebSocket("wss://ws.postman-echo.com/raw");
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#!/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;