Connecting to the echo port (7)

The echo port 7 will return a datagram that contains the exact contents of what was sent to it.
On many systems, this port is being disabled, fearing hackers may use it to perform a denial-of-service attack of some sort.

Just open a socket and write a line. If the port is enabled, the return will be the exact line.

EchoClient.java:

import java.util.*;
import java.net.*;
import java.io.*;
 
public class EchoClient {
   public static void main(String args[]) {
      if (args.length != 1) {
         System.out.println("java EchoClient <server>");
         System.exit(1);
      }
 
      try {
         Socket socket = new Socket(args[0], 7);    // 7 is echo port
         BufferedReader br = new BufferedReader(
                                new InputStreamReader(socket.getInputStream()));
 
         // true = autoflush
         PrintWriter pw = new PrintWriter(
                                new OutputStreamWriter(socket.getOutputStream()), true);  
 
         pw.println("Hello, world!");
 
         String ret = br.readLine();
         System.out.println(ret);
 
         socket.close();       
      }
      catch(Exception e) {
         e.printStackTrace();
      }
   }
}

java EchoClient www.compapp.dcu.ieoutputs:

Hello, world!