Getting UDP Status


To get status of UDP, get command of pid_ioctl function is required.

$return = pid_ioctl($pid, "get ITEM");

Available UDP States

ITEM Description Return Value Return Type
srcaddr source IP address e.g. 192.168.0.1 string
srcport source port number e.g. 1470 integer
dstaddr destination IP address e.g. 192.168.0.2 string
dstport destination port number e.g. 1470 integer
rxlen received data size[Byte] e.g. 200 integer

Received Data Size

To get received data size, "get rxlen" command of pid_ioctl function is required.

<?php
$rxlen = pid_ioctl($pid, "get rxlen");
?>

example

This example is closed after printing received data size if data comes from network while checking periodically whether there is data or not.

<?php
$rbuf = "";
$pid = pid_open("/mmap/udp0");              // open UDP 0
pid_bind($pid, "", 1470);                   // binding
do
{
    $rxlen = pid_ioctl($pid, "get rxlen");  // get received data size
    if($rxlen)
    {
        pid_recvfrom($pid, $rbuf, $rxlen);  // receive data
        echo "$rxlen bytes\r\n";            // print size of received data
    }
    usleep(100000);
}while($rxlen == 0);                        // while receiving no data
pid_close($pid);
?>