0
我正在开发一个多人游戏项目,我对如何设置它有点困惑。主要是因为我不熟悉Netty框架。网络设计[使用Netty]
每个玩家都应该拥有自己的Pipe来处理数据包吗?或者应该只有一个管道来处理所有入站数据包?
如果一个球员应该有自己的数据包,我将如何让该球员成为管道的拥有者?
目前,这是我的服务器代码
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();
}
}