简体   繁体   中英

Is there any way to detect java server application is online automatically through android app?

I'm working on a android application which makes client server communication over Socket. The server is on java application(desktop) & client is android app. Problem: I don't want the user to go and connect to it. I just want the app to detect that the java app is online and connect to it automatically without knowing the user.

Assuming your android app is coded in java.

For communication to server I would use something like this:

@Override
    public void run() {
        if (connected == false)
            {
              hostAvailabilityCheck();
            }
        }
    };

public static boolean hostAvailabilityCheck() { 
    try (Socket s = new Socket(SERVER_ADDRESS, TCP_SERVER_PORT)) {
        return true;
    } catch (IOException ex) {
        /* if errors */
    }
    return false;
}

Anyway, I cant help you any further because I dont know how your code looks like.

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