抱一点期望,有热心人能帮小弟我看看socket的有关问题

WBOY
Release: 2016-06-13 12:48:30
Original
1015 people have browsed it

抱一点期望,有热心人能帮我看看socket的问题
想实现这样的功能:
    向整个局域网发送广播,
    然后获取全部的返回信息。

<br />
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);<br />
socket_set_option($socket, SOL_SOCKET, SO_BROADCAST, 1);<br />
$message="1000";<br />
@socket_sendto($socket,$message,strlen($message),0,"255.255.255.255",6000);<br />
<br />
$ip="";<br />
$port=6000;<br />
@socket_recvfrom($socket,$message,0,0,$ip,$port);<br />
Copy after login


广播好像成功了,但是接收的代码好像有问题,上述代码会停不下来
其原因是有的ip没有返回结果,这个代码好像会一直等
我改为不等,但是所有返回结果都抓取不到了……

希望有热心人帮忙看看


------解决方案--------------------
是否成果应检查 socket_sendto 的返回值
参数 addr 好像不对吧? udp 方式应该是网段的最后一个地址
比如
192.168.5.0/24
那么网段为 192.168.5.0 掩码 255.255.255.0 广播地址为 192.168.5.255

socket_recvfrom 是侦听,好像你的 $ip 是空的嘛
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template