Tuesday, February 11, 2014
How to know how many Android devices within a wifi LAN hosts?
Android devices should be the means by which to enumerate all hosts on the LAN (where hosts mainly refers to Android devices) do? By sending broadcast it? Or framework layer provide API support? Still must rely on the development of native layer?
Reply:
Try cycling Runtime.getRuntime in the absence of agreement between the two sides () exec ("ping" + ip + "-i 1-c 2");. Ping each IP
. Runtime.getRuntime () exec ("arp-a>" + savefile); go handle this file
savefile
Another is to send udp broadcast, the requesting party and the command ip broadcast itself out, the device receives command will use its own ip tcp / udp sent to the requester.
Each device to establish Socket listen to the broadcast can.
Reply:
arp-a command displays the local ARP cache table, if the device had not been connected to other devices within the LAN, then, arp-a return in addition to a router, the other addresses should never return, right?
And I use "adb shell arp" The result is arp not found.
Reply:
Never used WIFI, Bangding
Reply:
Yes, it is a front to try this one ip ping, finally can show arp-a ip into a
onlinearp not found. Do not use the simulator, try using a real machine. I have arp command with the development board. No going busybox installed, and there are a lot of linux common commands
Reply:
I'm using is a real machine, it looks like you said, do you want to install busybox it.
Now, google provided by WifiManager class, I can already get the current IP devices, gateway, and subnet mask. In this case, I can already calculated that all possible within the current LAN IP address.
However, using ping and arp-a which means I need to create a lot of process (once per ping, a process, coupled with the arp process, assuming that a subnet mask of 255,255,255,0, in that case, creating a total of 256 process), this program is not detrimental to the performance of it?
Reply:
Yesterday tried udp broadcast, udp inherently unreliable protocol, coupled with the unreliability wifi wireless network, according to my tests, in our company's wifi network, packet loss rate of 50% basic and down, really is not very fly. . .
Reply:
Well this is actually a real machine to measure the job
Reply:
I have been using the real machine.
However, the company's wifi network seems to really not very good, two tablet PCs ping each time, often more than 1000 ms delay.
Currently about how to find other devices within the LAN, I have two options:
1.UDP broadcast, AP course in running, stop sending UDP broadcast (for example, once every second), then the receiving end of broadcast packets received inspected once every 10 seconds, and if found acceptable within the last 10 seconds been to a broadcast IP packets sent, then that IP is located on the machine that is running my AP (simple terms, is this machine line), the receiver can communicate with it. Considering the packet loss rate of the network, it can increase the transmission frequency of the transmission side or the receiving side scan interval increases to improve reliability.
2 Using TCP polling. Through the local IP and subnet mask, calculate all possible within the subnet IP address, the IP address of the polling, try Socket.connect (SocketAddress remoteAddr, int timeout) to make the connection, can connect to the machine is considered online. Timeout judged machine offline. However, in this case, the value of timeout is set too small, then the poor performance in the network (on wifi network in our company for example), easy to miss the device, timeout setting value is too large, the polling time it takes too much. The benefits of TCP packet loss problem is solved, but polling is too time-consuming, the use of multi-threading, it can indeed be shortened polling time, but they caused too much load.
Who can give me a better solution ah?
Reply:
Operating somewhat frequent and account for resources, and if you have a password and routing support IP routing queries then directly open the web page for the route on the line
For example, you can directly get http://192.168.2.1/DEV_device.htm
Reply:
This is difficult to ensure. . . . . . Just because the company's environmental development environment, what happens after the operating environment, difficult to say ah
Reply:
Eventually chose udp broadcast.
Although the speed asynchronous socket connection is indeed much faster than blocking, but the network is still bad situation Jiabu Zhu ah. Sweep the entire subnet IP address (254), slow time to one minute, the way too much ah.
Reply:
The landlord can give a demo it? I also do this 512573717@qq.com
Reply:
Hope that the landlord can give a demo, how to solve this problem very grateful! iewell@qq.com
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment