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
use warnings;
my ($data,$length);
# flush after every write
$| = 1;
# creating object interface of IO::Socket::INET modules which internally creates
# socket, binds and connects to the TCP server running on the specific port.
my $socket = new IO::Socket::INET (
PeerHost => 'localhost',
PeerPort => '8888',
Proto => 'tcp',
Blocking => 0,
) or die "ERROR in Socket Creation : $!\n";
print "TCP Connection Success.\n\n";
# read the socket data sent by server.
....
#while(1)
# {
$data= "read -m 60 -c heatpump mode";...
$socket->send("$data\n");
sleep 5;
$socket->recv($data,2048);
print ("Received from Server : $data\n\n");
# }
$data= "read -m 60 -c heatpump mode2";..
$socket->send("$data\n");
sleep 5;
$socket->recv($data,2048);
print ("Received from Server : $data\n\n");
1 2 3 4 5 6 7 8
$data= "read -m 60 -c heatpump mode2";.. $socket->send("$data\n"); sleep 5; $data = ''; while ( my $line = <$socket> ) { $data .= $line; } print ("Received from Server : $data\n\n");