1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| <meta charset="utf-8"> <?php
$server = 'udp://192.168.253.1:9998';
$msg_eof = "\n"; $socket = stream_socket_server($server, $errno, $errstr, STREAM_SERVER_BIND); if (!$socket) { die("$errstr ($errno)"); }
do { $inMsg = stream_socket_recvfrom($socket, 1024, 0, $peer); echo "Client : $peer\n"; echo "Receive : {$inMsg}"; $outMsg = substr($inMsg, 0, (strrpos($inMsg, $msg_eof))).' -- '.date("D M j H:i:s Y\r\n");
stream_socket_sendto($socket, $outMsg, 0, $peer);
} while ($inMsg !== false);
?>
|