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:
PIPEs and Sockets: not working.. but why???

 



pedrete
New User

Oct 29, 2012, 12:43 PM

Post #1 of 2 (840 views)
PIPEs and Sockets: not working.. but why??? Can't Post

Hello everybody...

Can anyone give me his/her opinion on this, please???

i am trying to use a "|-" Pipe to communicate 2 processes and it works OK when the parent just prints a
string to the chlid via PIPE. But when the the parent process tries to print to child via PIPE something it
got from a TCP socket, it does not work... :-(

This code shows what i am trying to do.... i mark in red the important area ($linea is never printed to "TO")

(I omit all the communications code to reduce post size)


Code
  if ( open(TO,"|-") ) {  
# Parent

while(1){
accept (SOCK, SOCK_SERVER);
$linea=<SOCK>;
print TO "$linea \n";
close SOCK;

}
}
else {
# Child
while(1){
$entrada=<STDIN>;
print " Received in Child: $entrada ";
}
}


The Child never prints anything! :-



if i change the red area and write it like next code (just to test the PIPE), it works!!! so the problem seems to be
<SOCK> related???????? :-( please, help!!


Code
  if ( open(TO,"|-") ) {  
# Parent

while(1){
$linea="HELLO";
print TO "$linea \n";

}
}
else {
# Child
while(1){
$entrada=<STDIN>;
print " Received in Child: $entrada ";
}
}



Thanks in advance for your help...

Pedrete


(This post was edited by pedrete on Oct 29, 2012, 12:44 PM)


rovf
Veteran

Oct 30, 2012, 2:07 AM

Post #2 of 2 (830 views)
Re: [pedrete] PIPEs and Sockets: not working.. but why??? [In reply to] Can't Post

I notice that you don't check whether the accept call succeeds.

I personally would not explicitly code the socket connection logic with accept, but instead use IO::Socket::INET, which is a standard module in Perl, and already takes care of error handling etc.

 
 


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

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