[英]How to send data to the same application installed on other android device using wifi
i have an application on my android device like "A" and same application installed on the other android device like "B", now i want to send data from app "A" to app "B" using WIFI service. 我在我的Android设备上有一个应用程序,如“A”和安装在其他Android设备上的相同应用程序,如“B”,现在我想使用WIFI服务从应用程序“A”发送数据到应用程序“B”。 so please suggest me how can i implement this feature. 所以请建议我如何实现此功能。
i tried many times to get help from google but all is vain. 我多次尝试从谷歌获得帮助,但一切都是徒劳的。 it is possible from WIFI direct or NFC. 它可以从WIFI直接或NFC。
You could use a simple p2p architecture. 您可以使用简单的p2p架构。
You will need to use this , this and a pair of streams that works with the kind of data you need to send, like this . 您将需要使用this , this和一对与您需要发送的数据类型相关的流,如下所示 。
On sender side: 在发件人方面:
Socket s = new Socket(IP,PORT);
s.connect();
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
dos.write("hello".toByteArray());
Then on receiver side: 然后在接收方:
ServerSocket ss = new ServerSocket(PORT);
Socket s = ss.accept(); //This call will block execution, use separate thread
DataInputStream dis = new DataInputStream(s.getInputStream);
byte[] data = dis.read();
With this you can send and receive bytes, just use the stream that works with your data type. 使用此功能,您可以发送和接收字节,只需使用适用于您的数据类型的流。
Of course, once connection is established, both clients could send/write, just make the appropiate Input/Output Stream. 当然,一旦建立连接,两个客户端都可以发送/写入,只需制作适当的输入/输出流。
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.