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();
}
}