
import java.io.*;
import java.net.*;
import java.util.*;

public class Server extends Thread
{
	public static final int MYPORT = 6700;
	ServerSocket listen_socket;
	
	public Server()
	{
		try{
			listen_socket = new ServerSocket (MYPORT);
			
		}
		catch(IOException e) {System.err.println(e);}
		this.start();
	}
	public void run()
	{
		try{
			while(true)
			{
				Socket client_socket = listen_socket.accept();
				Connection c = new Connection (client_socket);
			}
		}
		catch(IOException e) {System.err.println(e);}
	}
	public static void main(String[] argv)
	{
		new Server();
	}
}

//read an input, write something to the client, and quit
class Connection extends Thread
{
	protected Socket client;
	protected DataInputStream in;
	protected PrintStream out;
	public Connection (Socket client_socket)
	{
		client = client_socket;
		try{
			in = new DataInputStream(client.getInputStream());
			out = new PrintStream (client.getOutputStream());
		}
		catch(IOException e) 
		{
		 	System.err.println(e);
			try {client.close();} 
			catch (IOException e2) {};
			return;
		}
		this.start();

	}

	public void run()
	{
		String line;
		Date d;
		OutputStream os;
		try{
		
				line = in.readLine();
				d = new Date();
				out.println(d.toString());
		
		}
		catch (IOException e) {}
		finally
		{
			try {client.close();}
			catch (IOException e) {};

		}


	}
	
}
