1 20 package org.apache.mina.example.reverser; 21 22 import org.apache.mina.common.IoHandler; 23 import org.apache.mina.common.IoHandlerAdapter; 24 import org.apache.mina.common.IoSession; 25 26 32 public class ReverseProtocolHandler extends IoHandlerAdapter { 33 public void exceptionCaught(IoSession session, Throwable cause) { 34 cause.printStackTrace(); 35 session.close(); 37 } 38 39 public void messageReceived(IoSession session, Object message) { 40 String str = message.toString(); 42 StringBuffer buf = new StringBuffer (str.length()); 43 for (int i = str.length() - 1; i >= 0; i--) { 44 buf.append(str.charAt(i)); 45 } 46 47 session.write(buf.toString()); 49 } 50 } | Popular Tags |