Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cnc;
- import org.apache.mina.core.service.IoHandler;
- import org.apache.mina.core.session.IdleStatus;
- import org.apache.mina.core.session.IoSession;
- import org.apache.mina.filter.FilterEvent;
- import userInterface.UInterface;
- public class CNCServerHandler implements IoHandler {
- UInterface ui = new UInterface();
- public String getUser;
- private String getPass;
- @Override
- public void sessionCreated(IoSession session) throws Exception {
- // TODO Auto-generated method stub
- }
- @Override
- public void sessionOpened(IoSession session) throws Exception {
- // TODO Auto-generated method stub
- }
- @Override
- public void sessionClosed(IoSession session) throws Exception {
- // TODO Auto-generated method stub
- }
- @Override
- public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
- System.out.println(getContextInfo(session) + "Idle "+session.getIdleCount(status));
- }
- @Override
- public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
- cause.printStackTrace();
- }
- @Override
- public void messageReceived(IoSession session, Object message) throws Exception {
- session.write("Username: ");
- getUser = message.toString();
- session.write(ui.prompt());
- String cncCmd = message.toString();
- if(cncCmd.trim().equalsIgnoreCase("quit")) {
- session.write("Bye");
- session.closeOnFlush();
- return;
- } else {
- }
- }
- @Override
- public void messageSent(IoSession session, Object message) throws Exception {
- // TODO Auto-generated method stub
- }
- @Override
- public void inputClosed(IoSession session) throws Exception {
- // TODO Auto-generated method stub
- }
- @Override
- public void event(IoSession session, FilterEvent event) throws Exception {
- // TODO Auto-generated method stub
- }
- private String getContextInfo(IoSession session) {
- return Thread.currentThread().getName() + " " + session.getId() + " ";
- }
- }
Add Comment
Please, Sign In to add comment