With a little hope, some enthusiastic people can help me look at socket problems and want to implement 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, "commandid 255.255", 6000); $ ip = ""; $ port = 6000; @ socket_recvfrom ($ socket, $ message, $ 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.
Reply to discussion (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
The moderator is awesome. the moderator must be correct.
Thank you for your reply.
I need a full-network broadcast. If someone responds, I want to get this response.
$ The ip address is empty. it seems that the parameter can be passed in this way, because you are not sure which ip address will respond.
(Who can lend me some money? Two people may agree. I have one here. I want to get the content they promised)
Maybe there are other ways of writing?