How to send data to the same application installed on another Android device using wifi

I have an application on my Android device of type “A” and the same application installed on another Android device of type “B”, now I want to send data from application “A” to application “B” using the WIFI service. so please suggest me how can I implement this function.

I tried many times to get help from Google, but all in vain. It is possible from WIFI direct or NFC.

+4
source share
1 answer

You can use simple p2p architecture.

this, this , , , this.

:

Socket s = new Socket(IP,PORT);
s.connect();
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
dos.write("hello".toByteArray());

:

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();

, , .

, , /, /.

, .

+4

Source: https://habr.com/ru/post/1609239/


All Articles