首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在覆盆子上用PHP7接收多个广播

在覆盆子上用PHP7接收多个广播
EN

Stack Overflow用户
提问于 2016-07-22 08:16:22
回答 1查看 94关注 0票数 1

我通过PHP (v7.0.8-5)发送多播,到目前为止,这看起来还不错。

我的问题是我不能接收到这些小伙伴。

代码很好,无需防火墙就可以工作。

这是密码。

代码语言:javascript
复制
<?php
error_reporting(E_ALL | E_STRICT);
$mesg = "123456789012" ; //the msg i want to send

$ip = "228.5.6.7"; //the ip to send
$port = 14446 ;    //the port to send

//build the socket
$grpparms = array("group"=>$ip,"interface"=>"eth0") ;
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_set_option($sock,IPPROTO_IP,MCAST_JOIN_GROUP,$grpparms);   

if($argv[1] == 'r'){ //read multicasts
    $from = '';
    $dest_port = 0;

    $binded = socket_bind($sock, '0.0.0.0',$port);
    socket_recvfrom($sock, $buf, 12, 0, $from, $dest_port);
    echo "Received $buf from remote address $from and remote port $dest_port" . PHP_EOL;
}
if ($argv[1] =='w'){ //write multicasts
    socket_sendto($sock, $mesg, strlen($mesg), 0, $ip,$port);
    echo "Send '$mesg' to $ip at port $port".PHP_EOL;
    socket_close($sock) ;
}
?>

我称它为参数“r”来读/接收,用“w”来发送/写多个广播。

我在两个不同的raspberrys (Vers )上通过ssh启动这个脚本。2b)在同一开关上。一个是'r‘,另一个是'w’。

EN

回答 1

Stack Overflow用户

发布于 2016-07-22 13:12:31

我现在无法亲自测试它,但是请将socket_recvfrom()中的socket_recvfrom()更改为$port,或者将$dest_port的值从0更改为14446,然后再试一次。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38521482

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档