You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
725 B
Java
24 lines
725 B
Java
Ping a server
|
|
|
|
import java.io.*;
|
|
import java.net.*;
|
|
|
|
public class PseudoPing {
|
|
public static void main(String args[]) {
|
|
try {
|
|
Socket t = new Socket(args[0], 7);
|
|
DataInputStream dis = new DataInputStream(t.getInputStream());
|
|
PrintStream ps = new PrintStream(t.getOutputStream());
|
|
ps.println("Hello");
|
|
String str = is.readLine();
|
|
if (str.equals("Hello"))
|
|
System.out.println("Alive!") ;
|
|
else
|
|
System.out.println("Dead or echo port not responding");
|
|
t.close();
|
|
}
|
|
catch (IOException e) {
|
|
e.printStackTrace();}
|
|
}
|
|
}
|