Ping a server
import java.io.DataInputStream; import java.io.PrintStream; import java.net.Socket; public class Main { public static void main(String[] argv) throws Exception { Socket t = new Socket("127.0.0.1", 7); DataInputStream dis = new DataInputStream(t.getInputStream()); PrintStream ps = new PrintStream(t.getOutputStream()); ps.println("Hello"); String str = dis.readUTF(); if (str.equals("Hello")) System.out.println("Alive!"); else System.out.println("Dead"); t.close(); } }