pid_send()


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

Description

pid_send() sends $len bytes from the $buf to the network device $pid

※ available F/W version : all

Parameters

Return values

On success, the number of sent bytes is returned. -EPIPE is returned if the network session is closed. Otherwise PHP error. The return value may differ from the $len because of the network status.

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_recv() / pid_ioctl()

Remarks

None