package mina;

import java.util.*;
import org.apache.mina.core.service.*;
import org.apache.mina.core.session.*;

public class TimeServerHandler extends IoHandlerAdapter {
	
	public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
        cause.printStackTrace();
    }
	
    public void messageReceived(IoSession session, Object message) throws Exception {
        String str = message.toString();
        if (str.trim().equalsIgnoreCase("quit")) {
            session.close();
            return;
        }
        
        Date date = new Date();
        session.write(date.toString());
        System.out.println("Message written...");
    }
    
    public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
        System.out.println("IDLE " + session.getIdleCount(status));
        System.out.println(status);
    }
}
