2012-03-27 215 views
2

服務器工作正常,但問題是客戶端沒有收到任何東西。PHP套接字UDP通信

server.php

<?php  
$buf_size = 1024; 
$socket = stream_socket_server("udp://127.0.0.1:3127", $errno, $errstr, STREAM_SERVER_BIND); 
do { 
    $str = stream_socket_recvfrom($socket, $buf_size, 0, $peer); 
    $str = "abc"; 
    stream_socket_sendto($socket, $str, strlen($str), 0, $peer);  
} while (true); 
?> 

client.php

<?php 
$fp = stream_socket_client("udp://127.0.0.1:3127", $errno, $errstr); 
if (!$fp) { 
    echo "$errno - $errstr<br />\n"; 
} else {  
    fwrite($fp, "1 2 3");  
    echo fread($fp, 15); 
    fclose($fp); 
} 
?> 

回答