import java.net.*;
import java.io.*;

public class Net2 {
	public static void main(String argv[]) {
		new Thread( new PortEcho(80) ).start();
		new Thread( new PortEcho(81) ).start();
	} //main()
} //class Net2

class PortEcho implements Runnable {
	private int port;
	private ServerSocket servSock1 = null;
	private Socket sock1 = null;
	private InputStream in = null;
	private InputStreamReader isr = null;
	
	public PortEcho (int port) {
		this.port = port;
		try {
			servSock1 = new ServerSocket(port);
			sock1 = servSock1.accept();
			System.out.println("listening at port "+port);
		} catch (IOException io) {
			System.out.println("an IOException occurred\n"+io.toString()+"\n"+io.getMessage() );
		} //catch
	} //constructor
	public void run() {
		try {
			in = sock1.getInputStream();
			isr = new InputStreamReader(in);

			int c; 
			while ( (c = isr.read()) != -1 ) {
				System.out.println("("+port+") " + (char) c);
			} //while
		} catch (IOException io) {
			System.out.println("an IOException occurred\n"+io.toString()+"\n"+io.getMessage() );
		} //catch
	} //run()
} //class PortEcho
	