Re: upd sockets

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



dwa wrote:
Hey,
i have got a problem and cannot find answer.
I have got an process which sends real time data per udp. i can catch this packets and write to a site with php and sockets.

CODE
<?php
    define('LISTEN_IP',    '0.0.0.0');
    define('LISTEN_PORT',    52700);
    define('PACKET_SIZE',    1024);
    include("common.inc");
if ( $socket = @stream_socket_server('udp://'.LISTEN_IP.':'.LISTEN_PORT, $errno, $errstr, STREAM_SERVER_BIND) ) { ?>

<html>
<head>
    <title>php-test</title>
    <script language=JavaScript>
        function alarma() {
            alert("ARLAMA: <?php echo getAPaket() ?>");
        }
        </script>


</head>


<body>
<h2>Welcome to me</h2>
<p>listen to port 52776</p>
<?php
echo 'used socket '.$socket; $packet = '';
    $ilauf = 0;
    while ($ilauf < 10) {
//$buff = stream_socket_recvfrom($socket, PACKET_SIZE, 0, $remote_ip);
        $buff = stream_socket_recvfrom($socket, PACKET_SIZE, STREAM_OOB);
$packet .= $buff.'<br><br>';
       $ilauf++;
       echo 'current paketnummer is:'.$ilauf.'<br>';
echo 'current paket content:'.$buff.'<br><br>'; } fclose($socket);echo getAPaket();
}
EDOC

In this example i read ONLY 10 packets BUT i want to read the data continuous AND write the last received packet into a table. Now,
i write the data among each other. need a good idea! Ajax? js?
i thing, that the biggest prob. is that php is server sided a php
cleint sided...

Any IDEA??? Please answer here AND write an email to me. Because i ve
only an modem ;-( "wanscha @ web.de"

THX
dave

Well, sounds to me what you need to do is setup a PHP CLI daemon, using inetd or something. Have that running all the time logging the information it receives to a file.

Then, have a web page that when initially loaded reads a data file that has been populated by the daemon. Then displays all the initial data.

Then on that web page, have an AJAXy thingy that calls to the server with a time stamp of the last time the page was loaded or the last time it asked for an update. If the time of the log file is past that timestamp, then you can either reload the data, or figure out where in the data you need to start reading from that point to the end and then append that to the end of your existing table or data set in the current web page.

Then wait a given time frame and do it again. This time passing the updated timestamp.

Just a few ideas...

--
Jim Lucas


    "Perseverance is not a long race;
        it is many short races one after the other"

Walter Elliot



    "Some men are born to greatness, some achieve greatness,
        and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux