Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^4: IO Socket buffer flushing

by Arvind (Initiate)
on Apr 09, 2010 at 14:53 UTC ( [id://833834]=note: print w/replies, xml ) Need Help??


in reply to Re^3: IO Socket buffer flushing
in thread IO Socket buffer flushing

Here is the code. I am new to perl programming. I have to spawn four sub processes but initially trying to get 1 process to send the files. So the same socket connection is used to send the data and wait till they give us response and receive the response and write to a file.

my $BUFSIZE = 32000; my $varhex3= "\x03"; $SIG{USR1} = "doneit"; # I added the below for trial and error not sure what this #does. my $nonblocking = 1; select(S); $| = 1; select(STDOUT); for( my $childcounter = 1; $childcounter <= 1; $childcounter++ ) { my $pid = fork(); if ($pid) { # parent push(@childs, $pid); } elsif ($pid == 0) { # child if ($childcounter == 1) { @mylist1 = @{$hash1{$childcounter}}; my $socket1 = &opensock(); $myport = $socket1->sockport(); foreach $File (@mylist1){ $BaseFName = basename($File); my $outputdir = "directory goes here"; my $outputfile = "$outputdir\/$BaseFName".".res"; open(INFILE,"$File"); $data=<INFILE>; close INFILE; # print $sock "$data"; $socket1->send ($data); open (RESPONSEFILE, ">$outputfile") or die $!; my $lastchar = ""; my $Stop_Read = 0; while (! $Stop_Read) { $lastchar = ""; $data1 = ""; recv($socket1,$data1,$BUFSIZE,0); sleep 2; my $mylen = length($data1); $lastchar = substr ($data1, $mylen-1, 1); # print STDOUT $data1; print RESPONSEFILE $data1; if ($lastchar == $varhex3){ $Stop_Read = 1; } } close RESPONSEFILE; } close($socket1); } } sub doneit { $gotone = 1; } sub opensock{ my $sock = new IO::Socket::INET ( PeerAddr => 'IP address', PeerPort => 'Port number', Proto => 'tcp', Listen => SOMAXCONN, Reuse => 1, Timeout => 60, ); die "Could not create socket: $!\n" unless $sock; #select (sock); $| = 1; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://833834]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-04-26 03:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found