File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes How to tell whether a computer is on&running? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "How to tell whether a computer is on&running?" Watch "How to tell whether a computer is on&running?" New topic
Author

How to tell whether a computer is on&running?

Michael Herrmann
Ranch Hand

Joined: Dec 06, 2003
Posts: 60
Hi,
I want to write a program that plays a sound when a computer, specified by it's ip address, comes online/is turned on. It would be great if I wouldn't have to write a client for the observed computer. I just want to know if there is someone at the end of the line at 123.34.12.345(just an example and a fake ip address of course). I could use functionality similar to the MS-Dos ping command, but my friend Google already told me that Java doesn't support such a low-level protocol as used for the ping requests.
Do you know any solution where the observed computer doesn't have to have something in it's autostart that listens on a port just for such higher-level ping requests?
Thanks in advance
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Even though Java doesn't support ICMP (ping), you can always call "ping" with java.lang.Runtime#exec()


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Michael Herrmann
Ranch Hand

Joined: Dec 06, 2003
Posts: 60
Thanks a lot, that's what I needed. As you can see, I'm quite new to Java. It's a pity that my App loses its platform independence this way, but I don't think there's an option.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Hello. What about trying to connect to a port of the host?
If the result is "java.net.ConnectException: Connection refused: no further information" that means the computer is reachable though there is no process listening at that port.
You might use the connect method that is able to throw a SocketTimeoutException.


SCJP2. Please Indent your code using UBB Code
 
jQuery in Action, 2nd edition
 
subject: How to tell whether a computer is on&running?