Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^3: IO Socket buffer flushing

by Corion (Patriarch)
on Apr 08, 2010 at 19:25 UTC ( #833600=note: print w/replies, xml ) Need Help??

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

You don't show us any code. You don't show us how you're writing the files. If you use a delimiter between the two files, it's far more likely that there is an error in your (non-socket) program logic that mixes up the content of the files. Also, I wouldn't bet on a single read corresponding to a single write on the other end.

Replies are listed 'Best First'.
Re^4: IO Socket buffer flushing
by Arvind (Initiate) on Apr 09, 2010 at 14:53 UTC

    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?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2023-09-26 08:00 GMT
Find Nodes?
    Voting Booth?

    No recent polls found