pid_recvfrom()


int pid_recvfrom ( int $pid, int/string &$buf [ , int $len, int $flags = 0, string &$addr, int &$port ] )

Description

pid_recvfrom() receives $len bytes of the incoming data from UDP socket’s buffer

※ available F/W version : all

Parameters

Return values

Returns the number of bytes received (it can be less than the $len). PHP error on error

Example

<?php
define("MAX_BUF", 100);

$buf = "";
$peer_addr = "";
$peer_port = 0;

$pid = pid_open("/mmap/udp0");
pid_bind($pid, "", 1470);

while(1)
{
    $rlen = pid_recvfrom($pid, $buf, MAX_BUF, 0, $peer_addr, $peer_port);
    if($rlen > 0)
    {
        echo "udp received from $peer_addr:$peer_port ($rlen bytes)\r\n";
        $wlen = pid_sendto($pid, $buf, $rlen, 0, $peer_addr, $peer_port);
        echo "udp echo sent: $wlen bytes\r\n";

        // send data another host
        $wlen = pid_sendto($pid, $buf, $rlen, 0, "10.3.0.52", 2000);
        echo "udp sent to another host: $wlen bytes\r\n";
    }
}
?>

See also

pid_open() / pid_close() / pid_bind() / pid_sendto()

Remarks

None