DeafPort

DeafPort.java is a simple Java program that listens on a port and never answers. It can be use to test how an application behaves when the remote connection is accepted (TCP level) but never answers.

import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class DeafPort {

    public static void main(String[] args) {
        try {
            DeafPort deafPort = new DeafPort();
            deafPort.listen(Integer.parseInt(args[0]));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void listen(int portNumber) throws Exception{
            ServerSocket socket = new ServerSocket(portNumber);
            Socket clientSocket = socket.accept();
            while (true) {
                try {
                    Thread.sleep(1000);
                }
                catch ( InterruptedException e ) {
                    System.out.println("Sleep awakened prematurely");
                }
            }

    }

}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License