我正在做一个多人游戏项目,我有点困惑如何设置它。主要是因为我不熟悉Netty框架。
每个玩家应该有自己的烟斗来处理数据包吗?还是应该只有一个管道来处理所有入站数据包?
如果一个玩家应该有他自己的包,我该如何让那个玩家成为管道的所有者?
目前这是我的服务器代码
public static void main(String[] params) throws Exception
{
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try
{
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 100)
.handler(new LoggingHandler(LogLevel.DEBUG))
.childHandler(new ChannelInitializer<SocketChannel>()
{
@Override
public void initChannel(SocketChannel channel) throws Exception
{
ChannelPipeline pipeline = channel.pipeline();
pipeline.addLast(new LoggingHandler(LogLevel.DEBUG));
pipeline.addLast("PacketHandler", new SinglePacketPipe());
System.err.println("Connection Established - Pipes constructed..");
}
});
ChannelFuture future = bootstrap.bind(SERVER_PORT).sync();
System.err.println("Server initialized..");
// When the server socket is closed, destroy the future.
future.channel().closeFuture().sync();
}
finally
{
// Destroy all executor groups
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}发布于 2014-07-21 23:57:57
根据定义,Netty中的通道总是有自己的管道。也就是说,如果你有1000个连接,你就有1000个管道。完全由您决定让它们在这些管道中拥有相同的处理程序集,或者让其中一些处理程序具有不同的管道配置。
注意,管道是动态可配置的。您可以决定在initChannel()或处理程序的channelRegistered()中添加/删除哪些处理程序(甚至在任何处理程序方法中)。
https://stackoverflow.com/questions/24809801
复制相似问题