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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



gtrdriver
New User

Jun 26, 2015, 12:17 AM

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

Hello

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.

Procedure:

- 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:


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.
....
#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");


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
GTR


Laurent_R
Veteran / Moderator

Jun 26, 2015, 3:29 AM

Post #2 of 4 (1422 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.


gtrdriver
New User

Jun 26, 2015, 3:40 AM

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

Hi

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
GTR


gtrdriver
New User

Jun 26, 2015, 4:09 AM

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

Hello

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

Best REgards
Axel

 
 


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

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