socket_recvfrom
socket_recvfrom
Receives data from a socket whether or not it is connection-oriented
**socket_recvfrom** Socket $socket string $data int $length int $flags string $address int $port
The function receives
bytes of data in from
on port (if the
socket is not of type ) using
. can be
used to gather data from both connected and unconnected sockets.
Additionally, one or more flags can be specified to modify the behaviour of
the function.
socket_recvfrom``length``data``address``port``AF_UNIX``socket``socket_recvfrom
The and must be
passed by reference. If the socket is not connection-oriented,
will be set to the internet protocol address of
the remote host or the path to the UNIX socket. If the socket is
connection-oriented, is null. Additionally,
the will contain the port of the remote host in
the case of an unconnected or
socket.
address``port``address``address``port``AF_INET``AF_INET6
socket
The must be a instance previously
created by socket_create().
socket``Socket
data
The data received will be fetched to the variable specified with
.
data
length
Up to bytes will be fetched from remote host.
length
flags
The value of can be any combination of
the following flags, joined with the binary OR ()
operator.
flags``|
address
If the socket is of the type type,
is the path to the file. Else, for
unconnected sockets, is the IP address of,
the remote host, or null if the socket is connection-oriented.
AF_UNIX``address``address
port
This argument only applies to and
sockets, and specifies the remote port
from which the data is received. If the socket is connection-oriented,
will be null.
AF_INET``AF_INET6``port
returns the number of bytes received,
or false if there was an error. The actual error code can be retrieved by
calling . This error code may be
passed to to get a textual explanation
of the error.
socket_recvfrom``socket_last_error``socket_strerror
Voorbeeld: example
<?php
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_bind($socket, '127.0.0.1', 1223);
$from = '';
$port = 0;
socket_recvfrom($socket, $buf, 12, 0, $from, $port);
echo "Received $buf from remote address $from and remote port $port" . PHP_EOL;
?>
This example will initiate a UDP socket on port 1223 of 127.0.0.1 and print at most 12 characters received from a remote host.
socket_recv``socket_send``socket_sendto``socket_create