With a little hope, some enthusiastic people can help me look at socket problems-php Tutorial

Source: Internet
Author: User
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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.