How send data through WiFi?

帅比萌擦擦* 提交于 2019-12-05 05:06:10

问题


In my Application I want to send files through WiFi to multiple users if they are using the same WiFi connection Without TCP. how to get the list of the users who are connected to a specified wify. I have tried with Samples But I didn't get anything .


回答1:


Wi-Fi peer-to-peer (P2P) allows Android 4.0 (API level 14) or later devices with the appropriate hardware to connect directly to each other via Wi-Fi without an intermediate access point (Android's Wi-Fi P2P framework complies with the Wi-Fi Alliance's Wi-Fi Direct™ certification program). Using these APIs, you can discover and connect to other devices when each device supports Wi-Fi P2P, then communicate over a speedy connection across distances much longer than a Bluetooth connection. This is useful for applications that share data among users, such as a multiplayer game or a photo sharing application

http://developer.android.com/guide/topics/connectivity/wifip2p.html You can also refer this link to know more about programmatically




回答2:


TCP is a great transport for file transfers, I don't think you'll ever come up with a reason to not use TCP to begin with. There is also no fancy built-in file-transfer protocol that all Andriod devices can handle, so you'll still need to develop a client.

Besides, robust and reliable discover is not entirely possible either without the devices having custom clients for your purposes installed. Each client would either need to actively disclose itself, or passively reply to requests.

Passive: each device can be "ping"ed using actual ICMP (does not mean it's an enabled device), TCP or UDP packets on the local subnet. Responding clients can thus be discovered bit by bit, and even share their scan results.

Active: a reverse approach would be to have each enabled client send out multicast datagrams and listen to them (similar to how ARP discovery works). See: http://developer.android.com/reference/java/net/MulticastSocket.html

Each client would then listen for incoming TCP connections with your file data and meta data in some structured, serialized manner and be ready to store and/or process these. Bonus points for authentication and authorization.

The enabled client approach (a device with a client), means that you can potentially develop cross-platform clients and have them talk to one another using your own discover and data transfer protocols.




回答3:


For that, you have to make connection. Using Wi-Fi, you can't directly communicate to client, means one to one communication(As Bluetooth). For that, you have to connect sender(in this case your mobile device) and receiver (other mobile device or anything) to one router or hub. And from that you can communicate with receiver.




回答4:


You can't find out from your app which are the other devices connected to the same wifi network without the other devices broadcasting that information somehow.

Some routers have that functionality embedded in them via an exposed API I think but you would then need to implement this on a per-router basis. You could handle this for example using http://www.polarcloud.com/tomato

Alternatively, you could use some kind of framework to handle this for you on the phone level. Android API 14+ has in fact a library for that. Take a look at the Wi-Fi peer-to-peer documentation. This API in particular only works with certain types of devices and is limited to API 14 or above.

Finally, you could implement it yourself. It shouldn't be hard. Whenever a device connects to a wifi network, you could send the SSID of the network using android.net.wifi.WifiInfo.getSSID to a server of yours. Then your app could query the server for other devices connected to the same SSID and allow for communication between them.

Hope it helps.




回答5:


First store ip address of different computer in an array. You can use thread for sending data to multiple users by sleeping the thread one by one after sending ,it will help u to do the same



来源:https://stackoverflow.com/questions/20296713/how-send-data-through-wifi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!