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);
    
    评论

报告相同问题?

悬赏问题

  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站