package PortForwarder;
import java.net.*;

// Written by Sean R. Owens, sean at guild dot net, released to the
// public domain.  Share and enjoy.  Since some people argue that it is
// impossible to release software to the public domain, you are also free
// to use this code under any version of the GPL, LPGL, or BSD licenses,
// or contact me for use of another license.
// http://darksleep.com/player
public class JustListen {
    
    int listenPort = 0;
    String destName = null;
    int destPort= 0;


    ServerSocket serverSocket = null;

    public JustListen(int listenPort) {
        this.listenPort = listenPort;
        try {
            serverSocket = new ServerSocket(listenPort);
        }
        catch(Exception e) {
            System.err.println("Exception creating serverSocket:"+e);
            e.printStackTrace();
        }
    }

    public void go() {
        while(true) {
            try {
                Socket inConnection = serverSocket.accept() ;
                System.err.println("New connection established with "+ inConnection);
                JustListenHandler inHandler = new JustListenHandler(inConnection);
            }
            catch(Exception e) {
                System.err.println("Exception in go:"+e);
                e.printStackTrace();
            }
            
        }

    }

    public static void main(String argv[]) {
        int listenPort = 0;
        if(argv.length != 1) {
            System.err.println("usage: JustListen listenPort");
            System.exit(1);
        }
        listenPort = Integer.parseInt(argv[0]);
        JustListen jl = new JustListen(listenPort);
        jl.go();
    }    
}