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;
}
-
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.
|