FtpServer 中ftp协议消息的解析

ftpserver中的业务逻辑同样封装在FtpHandler中,类似于MINA中的IoHandler,可以看他的源代码:

FtpHandler 写道
public interface FtpHandler {

void init(FtpServerContext context, Listener listener) throws Exception;


void sessionCreated(FtpIoSession session) throws Exception;


void sessionOpened(FtpIoSession session) throws Exception;


void sessionIdle(FtpIoSession session, IdleStatus status) throws Exception;


void exceptionCaught(FtpIoSession session, Throwable cause)
throws Exception;


void messageReceived(FtpIoSession session, FtpRequest request)
throws Exception;


void messageSent(FtpIoSession session, FtpReply reply) throws Exception;
}

 可以看到,FtpHandler的接口定义几乎和IoHandler一模一样,同样的sessionCreated等方法,调用的模式也是和IoHandler一样的。而和MINA所要求的IoHandler的交互就是需要FtpHandlerAdapter,将底层的消息等封装成FtpIoSession和FtpRequest。具体实现参见FtpHandlerAdapter。其实FtpHandlerAdapter什么都没做,只是单纯的new一个FtpIoSession或FtpRequest。

 

具体的ftp协议的解析,就是在DefaultFtpHandler#public void messageReceived(final FtpIoSession session, final FtpRequest request) throws Exception 中实现,

写道
String commandName = request.getCommand();
CommandFactory commandFactory = context.getCommandFactory();
Command command = commandFactory.getCommand(commandName);

 实现ftp命令的解析,好简单啊,比其他协议简单多了

然后就是从session中查找用于是否登录,类似于http中的session,不再废话

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值