upd sockets

This is a discussion on upd sockets within the PHP General forums, part of the PHP Programming Forums category; Hey, i have got a problem and cannot find answer. I have got an process which sends real time data ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-10-2007
dwa
 
Posts: n/a
Default upd sockets

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
Reply With Quote
  #2 (permalink)  
Old 09-11-2007
Jim Lucas
 
Posts: n/a
Default Re: [PHP] upd sockets

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:08 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0