1 |
package gdclient; |
2 |
|
3 |
use strict; |
4 |
use warnings; |
5 |
|
6 |
require Exporter; |
7 |
use IO::Socket; |
8 |
use Data::Dumper; |
9 |
|
10 |
our @ISA = qw( Exporter ); |
11 |
our @EXPORT = qw( gd_connect gd_disconnect gd_command ); |
12 |
|
13 |
|
14 |
my $sock; |
15 |
|
16 |
sub gd_connect { |
17 |
my $host = shift; |
18 |
my $port = shift; |
19 |
|
20 |
$host ||= `hostname -i`; |
21 |
$port ||= 26468; |
22 |
$sock = IO::Socket::INET->new(PeerAddr => $host, |
23 |
PeerPort => $port, |
24 |
Proto => 'tcp') or die($@); |
25 |
} |
26 |
|
27 |
sub gd_disconnect { |
28 |
$sock->close(); |
29 |
} |
30 |
|
31 |
sub gd_command { |
32 |
my $cmd = shift; |
33 |
my @args = @_; |
34 |
|
35 |
$sock->send(join("\t", $cmd, @args) . "\n"); |
36 |
} |
37 |
|
38 |
#my $data; |
39 |
#$sock->read(1024,$data) until $sock->atmark; |
40 |
|
41 |
|
42 |
############################################################################### |
43 |
1; |