This article is reprinted from the WeChat public account "Wangluo Development", written by Zhan Fei. Please contact the WeChat public account "Wangluo Development" to reprint this article. 1. Problem Background
The specific contents of the error are as follows:
2. Problem Analysis2.1 Troubleshooting sendto returns -1 We know that sending a broadcast sendto returns -1, and normally the sendto return value is greater than 0. First determine whether the socket connection is established
self._sck_fd4 prints:
The socket connection is normal, and then determine the data packet
Data sending failed 2.2 Add NSLocalNetworkUsageDescription permission
Found that the problem still exists 2.3 Troubleshooting unicast messages Since the hostName set for sending broadcast in the project is 255.255.255.255, in order to troubleshoot, we decided to send unicast first to see if it can succeed. After changing the unicast address to 192.168.0.101, it was found that it could be sent successfully. Then, sending unicast in the new version of CocoaAsyncSocket library was also successful. It is recommended to use 192.168.0.255 for UDP broadcast. After changing the broadcast address, the problem is solved and the device can receive UDP broadcast data. 3. Problem SolvingSince the 192.168.0.255 broadcast address is only the current local address, the first three segments of the 192.168.0 local address need to be changed dynamically in the App. The solution is as follows:
For packet filtering, you only need to filter whether the last segment of the address is 255.
|
<<: Hongmeng OS, Android, IOS, which one is the future?
>>: Android 12 is officially released: the biggest design change in Android history, smoother!
Guide to tea tasting resources in Chengdu: Senior...
The top scorers of the 2020 Lianjiang College Ent...
"What tools are needed for a complete event?...
As a bidder, setting up an account is a common th...
WeChat Phonebook is now online! How big of an imp...
Microsoft recently released a free version of its ...
The year 2018 has passed by in a flash. The prosp...
From October 18 to 25, 2021, the F-15EX Eagle II ...
[[147756]] Recently, the e-commerce startup comed...
On September 12, the AITO M7 series was officiall...
It is estimated that many people do not know much...
As summer comes to an end, the best time of the y...
Audit expert: Zhou Jiaojiao Associate Professor, ...
On May 18th every year, most museums around the w...