-
Notifications
You must be signed in to change notification settings - Fork 0
/
lonotify-client.pl
executable file
·57 lines (40 loc) · 996 Bytes
/
lonotify-client.pl
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
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl
use warnings;
use strict;
use IO::Socket::INET;
use Getopt::Std;
use feature qw(say);
## GLOBALS & default values ###
my $VERSION = "0.0.1"; # script version
my $DEBUG = 0 ;
### Standard Opt first : Help and version
sub VERSION_MESSAGE {
print "$0 version $VERSION\n";
exit 0;
}
sub HELP_MESSAGE {
print <<EOM;
Sends a message via Throwtext
EOM
exit 0;
}
use constant { PROTO_VERS => "V0.1" , PROTO_PORT => "4455" };
# First : Options
my %opts;
getopts('D:ht:m:', \%opts);
HELP_MESSAGE() if defined( $opts{'h'} );
$opts{'t'} = "Default title" unless defined $opts{'t'};
$opts{'m'} = "Default message" unless defined $opts{'m'};
my $data = pack("A*xA*xA*", PROTO_VERS, $opts{'t'}, $opts{'m'});
say "DBG: $data";
# auto-flush on socket
$| = 1;
my $socket;
$socket = new IO::Socket::INET (
PeerAddr => 'localhost:' . PROTO_PORT,
Proto => 'tcp'
);
die "Cannot create socket: $!\n" unless $socket;
print "Connected\n";
$socket->send($data);
$socket->close();