简体   繁体   中英

Using IP address to Communicate with android device

I have the IP address and the mac address of an android device connected to a separate network. And I want to communicate with it using PHP or ajax , the android device isn't pre-registered and it can change. Thus the first contact is established by the device to send the IP and MAC addresses.

I want to be able to send and receive data with the device without his interaction, for instance, I can wait for the android device to contact the server and place an action in PHP like this:

if (isset($_GET['action'])) {
    $PageAction = $_GET['action'];
} else {
    $PageAction = 'NoAction';
}
switch ($PageAction) {
    case "first_action":
           echo "android_action_todo";    
        break;
   
    default:
        echo "No option is selected!";
}

the android device can now send to the URL of the server with /phpfile.php?action=first_action and get the echoed string android_action_todo .

I want to reverse this interaction to be able to send data from the server to the device so that I don't have to wait for the android player to make the first interaction , to be able to get the data in real-time and not have to wait for the android device, it may take seconds, minutes or hours even.

To enable your Android device to respond to an incoming request initiated by the server, you have a few options:

  • Have the Android device to be running a webserver, and for it to be exposed on the firewall / NAT router of the network it is on. Challenge: complex, and requires the network to be configured correctly.
  • Establish a websocket connection from the Android device to your server, and use this to initiate an operation from the server. Challenge: the device needs to be running the app / webpage.
  • Use Android push notifications.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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