doujiao2000 2014-01-28 18:41
浏览 120

为什么UDP数据包没有使用PHP fsockopen从客户端网页发送到服务器?

The following code sends out a UDP packet when I run it from my Linux server with the address of my web client udp://192.168.1.107:2159. However, when I call the same web page from the client with the address Linux server address shown in the code, NO UDP packet is emitted. I tried both a PC client with chrome and a Mac client with Safari. Also, the phpinfo() shows that allow_url_fopen is "On". Also, I tried the code without the fflush() function too.

Is there restrictions on Client web pages and PHP sockets? I don't see this searching the net. By the way, I coded a Java app on the same client machine and it sends the UDP packet to the address and port without problem.

phpinfo();

$errno = 0;
$errstr = "";
$fsocket = fsockopen("udp://192.168.1.103:2195", $errno, $errstr);
if( !$fsocket ) {
    echo "$errstr( $errno)<br/>
";
} else {
    $out = "Oh ya baby!
";
    fwrite( $fsocket, $out );
    fflush( $fsocket );
    fclose($fsocket);
}
  • 写回答

2条回答 默认 最新

  • douhuanchi6586 2014-01-28 18:46
    关注

    The port is the second argument to fsockopen(). It needs to get passed isolated from the domain name. Like this:

    $fsocket = fsockopen("udp://192.168.1.103", 2195, $errno, $errstr);
    
    评论

报告相同问题?