Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于message的建议 #1

Open
NickNYU opened this issue Apr 18, 2016 · 1 comment
Open

关于message的建议 #1

NickNYU opened this issue Apr 18, 2016 · 1 comment

Comments

@NickNYU
Copy link

NickNYU commented Apr 18, 2016

Hi 楼主,很高兴能在网上看到你的项目,让我能够自学的时候练习一把
现在刚刚把server部分实现完,client还没到

我在实现的时候发现BaseMsg这个类可以改进一下,我增加了一个方法

public abstract void dealWithServerMsg(ChannelHandlerContext ctx);

这样在ServerHandler端就可以用回调的方法来handle不同type的message,而且如果后期加入别的message,只用实现接口,而不用更改server的设置
if(msg.getClientId() == null) {
AbstractMsg loginMsg = new LoginMsg();
ctx.channel().writeAndFlush(loginMsg);
} else {
// 回调机制,由message本身来完成操作
msg.dealWithMessage(ctx);
}

可以互相交流一下哈

@WangErXiao
Copy link
Owner

good , 不错 ,数据 与 操作 分开 ,采用访问者模式也不错,采用回调的方式

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants