pid_recv()


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

Description

pid_recv() attempts to read up to $len incoming bytes from the internal buffer of the network device $pid into the buffer $buf

※ available F/W version : all

Parameters

Return values

On success the number of bytes received is returned, otherwise PHP error. It is not an error if this number is smaller than the number of bytes requested. This happen in the case the length of available data in device’s buffer is smaller than the requested length

Example

<?php
$buf = "";

$pid = pid_open("/mmap/tcp0");
pid_connect($pid, "10.3.0.10", 1470);
do
{
    $state = pid_ioctl($pid, "get state");  // get the current TCP state
    if($state == TCP_CLOSED)  // if TCP connection attempt fails, try to connect again
    {
        pid_connect($pid, "10.3.0.10", 1470);
        sleep(1);
    }
}while($state != TCP_CONNECTED);
echo "TCP connected\r\n";

while(1)
{
    $rlen = pid_recv($pid, $buf, 100);  // read the received data into $buf upto 100 bytes
    if($rlen > 0)
    {
        echo "tcp received: $rlen bytes\r\n";
        $wlen = pid_send($pid, $buf, $rlen, 0);
        echo "tcp echo sent: $wlen bytes\r\n";
    }
}
?>

See also

pid_open() / pid_close() / pid_send() / pid_ioctl()

Remarks

None