-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebsocket.pl
More file actions
executable file
·46 lines (34 loc) · 851 Bytes
/
websocket.pl
File metadata and controls
executable file
·46 lines (34 loc) · 851 Bytes
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/perl
# just testing for now
use Net::WebSocket::Server;
require "/usr/local/lib/bclib.pl";
my($ws)=Net::WebSocket::Server->new(listen=>8000,on_connect => \&connection);
debug("WS: $ws");
# this happens when connection occurs
sub connection {
my($serv, $conn) = @_;
debug("SERV: $serv, CONN: $conn");
$conn->on(utf8 => \&message);
}
# this happens when we get a message
sub message {
my($conn, $msg) = @_;
debug("GOT: $msg");
$conn->send_utf8("You said: $msg, the time is".`date`);
}
$ws->start;
=item sample_code
use Net::WebSocket::Server;
Net::WebSocket::Server->new(
listen => 8080,
on_connect => sub {
my ($serv, $conn) = @_;
$conn->on(
utf8 => sub {
my ($conn, $msg) = @_;
$conn->send_utf8($msg);
},
);
},
)->start;
=cut