Reputation: 118
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. 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.
Upvotes: 4
Views: 285
Reputation: 2381
You could use a simple p2p architecture.
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.
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.
Upvotes: 4