I want to send data from one Android device to another Android device which are connected to same router via wifi? Same App is installed on both devices and i want them to communicate each other connected to same router via wifi.
Asked
Active
Viewed 1,531 times
0
-
1Possible duplicate of [Android - communicating between two devices](http://stackoverflow.com/questions/9608832/android-communicating-between-two-devices) – Florian Koch Jul 21 '16 at 14:30
-
@FlorianKoch we have make use of Wi-Fi Peer-to-Peer? – Rajat Jul 21 '16 at 14:49
-
please clarify, I'm not sure what you mean. The answers of the other question also include information regarding connection via a router, not only direct, see [this answer](http://stackoverflow.com/a/26955220/3326982) – Florian Koch Jul 21 '16 at 14:52
3 Answers
0
Use socket connection with any of these protocols UDP, TCP or HTTP
Send message using UDP
String messageStr="Hello Android!";
int server_port = 12345;
DatagramSocket s = new DatagramSocket();
InetAddress local = InetAddress.getByName("192.168.1.102");
int msg_length=messageStr.length();
byte[] message = messageStr.getBytes();
DatagramPacket p = new DatagramPacket(message,msg_length, local,server_port);
s.send(p);
Receive UDP message
String text;
int server_port = 12345;
byte[] message = new byte[1500];
DatagramPacket p = new DatagramPacket(message, message.length);
DatagramSocket s = new DatagramSocket(server_port);
s.receive(p);
text = new String(message, 0, p.getLength());
Log.d("Udp tutorial","message:" + text);
s.close();

Community
- 1
- 1

Jayakrishnan
- 4,457
- 29
- 29
0
I'm also interested in this (sending data between two devices on a wireless network connection without internet), so I did a quick search and found another answer below.
Android - communicating between two devices
https://stackoverflow.com/a/26955220/6589689
Android Wireless API will also work if your devices are on the same local network (i.e., use the same WiFi router)
-
please don't answer only with links. Looking at your Link, the question seems like a duplicate - this means this question should be marked as duplicate instead of beeing answered (I know you can't do that just yet) – Florian Koch Jul 21 '16 at 14:30
0
Sockets are the way to accomplish this.
You'll need a way to discover the ip address and port of the socket you want to connect to. You can use Android network service discovery.
You can find a complete tutorial of how to build an app like this here

InnisBrendan
- 2,079
- 2
- 19
- 21