Hi
How can i know in java , pc is connected to internet or no (is online or offline) ???
thanks

You can try to ping well know IP like google servers and see if you get response

You can try to ping well know IP like google servers and see if you get response

how con i do this ???

how con i do this ???

By reading a few tutorials...

how con i do this ???

Here you go

Hi , i use this code for check connection but it`s work fine only in root user !!!

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;


public class Connection {

	/**
	 * @param args
	 */
	public static boolean status;
	public static void main(String[] args) {
		String host = "209.85.229.147";
        int timeout = 3000;
        try {
			status = InetAddress.getByName(host).isReachable(timeout);
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (status) {
            System.out.println("Online");
        } else {
            System.out.println("Offline");
        }


	}

}

how can i do it for normal user`s ???
thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.