CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Perl Socket - wait for Anwser


New User

Jun 26, 2015, 12:17 AM

Post #1 of 4 (1615 views)
Perl Socket - wait for Anwser Can't Post


Im not new in perl but im new in Socket Programming.

Goal: i want to connect to a linux deamon wich offer a Socket Interface.


- Connect to daemon
- Send command
- After deamon do some work recieve answer from daemon

I have searched all over on Net for some Examples so i made some quick and dirty code:

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.
# {
$data= "read -m 60 -c heatpump mode";...
sleep 5;
print ("Received from Server : $data\n\n");
# }

$data= "read -m 60 -c heatpump mode2";..
sleep 5;
print ("Received from Server : $data\n\n");

First of all - it works - but only with "sleep 5" command between send and REad command.

But sometimes the deamon taks longer to get Information then i get a emty message back.

How can i wait after send command for deamon is ready ?

Best Regards

Veteran / Moderator

Jun 26, 2015, 3:29 AM

Post #2 of 4 (1607 views)
Re: [gtrdriver] Perl Socket - wait for Anwser [In reply to] Can't Post

I haven't done any socket programming for more than 20 years and it was not in Perl at the time. I do not know this module at all. But maybe you should try to set Blocking to 1. I am just guessing that it might force the program to wait for the answer.

New User

Jun 26, 2015, 3:40 AM

Post #3 of 4 (1602 views)
Re: [Laurent_R] Perl Socket - wait for Anwser [In reply to] Can't Post


thanks for your reply
What do you mean with Blocking ?

Can you show me the part of the Code where to sent his ?

Best regards

New User

Jun 26, 2015, 4:09 AM

Post #4 of 4 (1601 views)
Re: [Laurent_R] Perl Socket - wait for Anwser [In reply to] Can't Post


sorry - now i see it - will test - Thanks a lot !

Best REgards


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives