/* Open a server socket to port 1234 on localhost */
$server = stream_socket_server('tcp://127.0.0.1:12345');
$socket = stream_socket_accept($server);
/* Grab a packet (1500 is a typical MTU size) of OOB data */
echo "Received Out-Of-Band: '" . stream_socket_recvfrom($socket, 1500, STREAM_OOB) . "'\n";
/* Take a peek at the normal in-band data, but don't comsume it. */
echo "Data: '" . stream_socket_recvfrom($socket, 1500, STREAM_PEEK) . "'\n";
/* Get the exact same packet again, but remove it from the buffer this time. */
echo "Data: '" . stream_socket_recvfrom($socket, 1500) . "'\n";
/* Close it up */
fclose($socket);
fclose($server);
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论