简体   繁体   English

android中两个设备之间的无线通信

[英]wireless communication between two devices in android

I have two different android applications running on two different android devices(let's say device1 and device2) and both devices are connected to the same WiFi network. 我在两个不同的android设备(假设device1和device2)上运行了两个不同的android应用程序,并且两个设备都连接到同一WiFi网络。

Now, I have to initiate a command from device1 which can be received by device2 and execute it and send the result back to device1. 现在,我必须从device1发起一个可由device2接收的命令并执行它,然后将结果发送回device1。

device1 doen't have any info about device2 ie ip address, device id etc.. , so first it has to identify the device2 where 2nd android app is running and then establish the connection and start doing communication. device1没有关于device2的任何信息,例如IP地址,设备ID等。因此,它首先必须标识正在运行第二个android应用程序的device2,然后建立连接并开始进行通信。

Please suggest me best possible way to achieve it. 请建议我实现它的最佳方法。

If the two devices are on the same sub-net it is actually easy. 如果两个设备在同一子网中,则实际上很容易。 Unit 1 sends a broadcast that unit 2 responds to. 单元1发送广播,单元2对此作出响应。 Now they both have IP address's of each other. 现在他们两个都有彼此的IP地址。

Below expains local IP broadcast. 下面说明本地IP广播。

http://en.wikipedia.org/wiki/Broadcast_address http://en.wikipedia.org/wiki/Broadcast_address

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM