With a little hope, some enthusiastic people can help me look at socket problems and want to implement such a function: & nbsp; send a broadcast to the entire LAN, & nbsp; & nbsp; then retrieve all returned information. $ Socket & nbsp; = & n have some expectations. some enthusiastic people can help me check socket problems.
To achieve this function:
Send broadcasts to the entire LAN,
Then retrieve all the returned information.
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_set_option($socket, SOL_SOCKET, SO_BROADCAST, 1);
$message="1000";
@socket_sendto($socket,$message,strlen($message),0,"255.255.255.255",6000);
$ip="";
$port=6000;
@socket_recvfrom($socket,$message,0,0,$ip,$port);
The broadcast seems to have succeeded, but the received code seems to be faulty. the above code will not be stopped.
The reason is that some ip addresses do not return results, and this code seems to always wait.
I changed it to a different one, but all returned results cannot be captured ......
Hope someone who is enthusiastic can help you.
------ Solution --------------------
Check whether the result is returned by socket_sendto.
Does the addr parameter seem wrong? Udp should be the last address of the network segment
For example
192.168.5.0/24
The IP address range is 192.168.5.0 mask 255.255.255.0. the broadcast address is 192.168.5.255.
Socket_recvfrom is listening, as if your $ ip is empty