I am trying to monitor the status of an agent from the web. The agent opens a UDP socket and consistently send messages reflecting its status on a non-regular basis. I have a script,listen.pl, that opens a socket,binds it to the web-server IP and listen for incoming messages.

What I have in mind is to dynamically update a web page everytime a new message comes in.I've tried the following:


1)open a filehandle on listen.pl and use a while loop to print each line to html. I realize the web page wouldn't show until the while loop terminates,i.e. it cant refreshes line by line while each line of meassage comes in.


2)I modify listen.pl to take in one message and then close the socket. Doing this, the message appears. However ,it's not what I wanted. Next, I put everything in a subroutine and call the subroutine twice.By right, the first call would have generated the first message and then followed by the second.However, all I get is a long wait and the 2 messages pop out at the same time. I tried both including and excluding the html starting/ending tags in the subroutine.


Does anyone have any suggestion how to do this properly? Also,I need a way of letting the cgi script knows when the browser window is closed so that it will stop running listen.pl.Thanks


In reply to Dynamic Updating of a HTML page by Anonymous Monk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.