Guest User

CNCServerHandler

a guest
Jun 2nd, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 KB | None | 0 0
  1. package cnc;
  2.  
  3. import org.apache.mina.core.service.IoHandler;
  4. import org.apache.mina.core.session.IdleStatus;
  5. import org.apache.mina.core.session.IoSession;
  6. import org.apache.mina.filter.FilterEvent;
  7.  
  8. import userInterface.UInterface;
  9.  
  10. public class CNCServerHandler implements IoHandler {
  11.  
  12.     UInterface ui = new UInterface();
  13.     public String getUser;
  14.     private String getPass;
  15.    
  16.     @Override
  17.     public void sessionCreated(IoSession session) throws Exception {
  18.         // TODO Auto-generated method stub
  19.        
  20.     }
  21.  
  22.     @Override
  23.     public void sessionOpened(IoSession session) throws Exception {
  24.         // TODO Auto-generated method stub
  25.        
  26.     }
  27.  
  28.     @Override
  29.     public void sessionClosed(IoSession session) throws Exception {
  30.         // TODO Auto-generated method stub
  31.        
  32.     }
  33.  
  34.     @Override
  35.     public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
  36.  
  37.         System.out.println(getContextInfo(session) + "Idle "+session.getIdleCount(status));
  38.        
  39.     }
  40.  
  41.     @Override
  42.     public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
  43.  
  44.         cause.printStackTrace();
  45.        
  46.     }
  47.  
  48.     @Override
  49.     public void messageReceived(IoSession session, Object message) throws Exception {
  50.  
  51.  
  52.         session.write("Username: ");
  53.         getUser = message.toString();
  54.  
  55.        
  56.         session.write(ui.prompt());
  57.         String cncCmd = message.toString();
  58.         if(cncCmd.trim().equalsIgnoreCase("quit")) {
  59.             session.write("Bye");
  60.             session.closeOnFlush();
  61.             return;
  62.         } else {
  63.            
  64.         }
  65.        
  66.     }
  67.  
  68.     @Override
  69.     public void messageSent(IoSession session, Object message) throws Exception {
  70.         // TODO Auto-generated method stub
  71.        
  72.     }
  73.  
  74.     @Override
  75.     public void inputClosed(IoSession session) throws Exception {
  76.         // TODO Auto-generated method stub
  77.        
  78.     }
  79.  
  80.     @Override
  81.     public void event(IoSession session, FilterEvent event) throws Exception {
  82.         // TODO Auto-generated method stub
  83.        
  84.     }
  85.    
  86.     private String getContextInfo(IoSession session) {
  87.         return Thread.currentThread().getName() + " " + session.getId() + " ";
  88.     }
  89.  
  90. }
  91.  
Add Comment
Please, Sign In to add comment