diff --git a/osgan-netty/src/main/java/dev/httpmarco/osgan/networking/server/CommunicationServer.java b/osgan-netty/src/main/java/dev/httpmarco/osgan/networking/server/CommunicationServer.java index 01299ba..5040ca6 100644 --- a/osgan-netty/src/main/java/dev/httpmarco/osgan/networking/server/CommunicationServer.java +++ b/osgan-netty/src/main/java/dev/httpmarco/osgan/networking/server/CommunicationServer.java @@ -31,7 +31,12 @@ public void initialize() { var bootstrap = new ServerBootstrap() .group(bossGroup(), workerGroup) .channelFactory(CommunicationNetworkUtils.generateChannelFactory()) - .childHandler(new ChannelInitializer(new CommunicationTransmitHandler(it -> this.channels, (it, channel) -> channel.call(it, channel), channelTransmit -> channels.add(CommunicationServerTransmit.of(channelTransmit, this))))) + .childHandler(new ChannelInitializer(new CommunicationTransmitHandler( + (it) -> this.channels, + (it, channel) -> channel.call(it, channel), + (it) -> channels.add(CommunicationServerTransmit.of(it, this)), + (it) -> channels.removeIf(channel -> channel.channel().equals(it.channel())) + ))) // all channel options .childOption(ChannelOption.TCP_NODELAY, true) @@ -46,6 +51,12 @@ public void initialize() { }); } + @Override + public void close() { + workerGroup.shutdownGracefully(); + super.close(); + } + @Override public void sendPacket(Packet packet) { this.channels.forEach(channelTransmit -> channelTransmit.sendPacket(packet));