Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hi, I have made a socket that connects to a remote server and listens for incoming data, it writes the data to a file. The data stream is continuous, any breaks in the stream are not based an any pattern. The code works mostly, except that a new file is never created. I would like a new file to be created every 15 minutes. I realize this is because an EOF is never reached from the socket, and the socket is blocking the code from moving forward. I am not sure making the socket non-blocking will get me what I want, as there will almost always be data in the buffer to be read. Is there a way to get the desired behavior? I was considering either trying to use Fork in some way, or making a seperate script to handle to file seperation with the current script writing to generic file. Thanks, Eric

while($continue){ if ($socket->connected){ $quarter = $minute - ($minute % 15); ## if quarter != quarter 15 minutes has passed, create + new filename with the next 0 15 30 45 designation if($cur_quarter != $quarter){ ## close current file and move it to directory + for further processing close $fout; move("$dir.$filename","/home/ed/falbee/chrysle +r_asn/lu62asns"); $cur_quarter = $quarter; ## pad cur_quarter with 0 (make sure has two d +igits) $cur_quarter .= '0' x (2 - length($cur_quarter +)); $filename ="$date$cur_quarter"; open ($fout, ">>", $filename); } local $/ = '^\'; my $line = <$socket>; print $fout $line; }

In reply to IO::Socket blocking question by ericf706

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found