Jump to content

netty server automatically close 1.15.2


nooblong
 Share

Recommended Posts

 

I make a netty server on mod.

 

@Mod.EventBusSubscriber(modid = MusicRestaurant.MOD_ID, value = Dist.DEDICATED_SERVER)
public class ServerEventSubscriber {

    @SubscribeEvent
    public static void serverStarted(FMLServerStartedEvent event){
        try {
            System.out.println("nettyStart");
            NettyServer.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
@OnlyIn(Dist.DEDICATED_SERVER)
public class NettyServer {

    public static final int PORT = 12333;

    static EventLoopGroup bossGroup = new NioEventLoopGroup();
    static EventLoopGroup workerGroup = new NioEventLoopGroup();

    public static void start() throws Exception {
        try {
            ServerBootstrap bootstrap = new ServerBootstrap();
            bootstrap.group(bossGroup, workerGroup);
            bootstrap.channel(NioServerSocketChannel.class);
            bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
                @Override
                protected void initChannel(SocketChannel ch) throws Exception {
                    ch.pipeline().addLast(new NettyServerHandler());
                }
            });
            ChannelFuture channelFuture = bootstrap.bind(PORT).sync();



            channelFuture.addListener(new ChannelFutureListener() {
                public void operationComplete(ChannelFuture channelFuture) throws Exception {
                    if (channelFuture.isSuccess()){
                        System.out.println("lister"+PORT+"success");
                    } else {
                        System.out.println("listen"+PORT+"fail");
                    }
                }
            });
        } finally {
            MusicRestaurant.LOGGER.error("ServerShutdown");
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }
    }

}

when server started, command line show 

[02:03:29] [Server thread/INFO] [STDOUT/]: [github.nooblong.mr.util.ServerEventSubscriber:serverStarted:20]: nettyStart
[02:03:29] [Server thread/ERROR] [gi.no.mr.MusicRestaurant/]: ServerShutdown
[02:03:29] [nioEventLoopGroup-2-1/INFO] [STDOUT/]: [github.nooblong.mr.upload.NettyServer$2:operationComplete:38]: listen12333success

why after "ChannelFuture channelFuture = bootstrap.bind(PORT).sync();"

it still close.

Link to comment
Share on other sites

13 hours ago, diesieben07 said:

Unless you really need to, you should not deviate from Minecraft's default networking as it will require potentially lots of extra setup for people using your mod (extra firewall rules, etc.) or make it even impossible (on server hosts which do not allow additional ports to be opened).

I use SImpleChannel to send message, it works on single player, but when I use server and client, client show 

internal exception io.netty.handler.codec.decoderException:java.io.IOExcepton: payload may not be larger than 32767 bytes

how to send larger files, or how to split it to send

Link to comment
Share on other sites

20 hours ago, diesieben07 said:

You already discovered how to do it: Split it into multiple packets.

one last question, 

Can I customize the ResourceLocation and Let it point to a folder at the same level as /mods

How should I modify the sounds.json?

I want to register resources dynamically in the game.

Link to comment
Share on other sites

 

2 hours ago, nooblong said:

one last question, 

Can I customize the ResourceLocation and Let it point to a folder at the same level as /mods

How should I modify the sounds.json?

I want to register resources dynamically in the game.

ok, i found how to do in SkinManager , thank you so much

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.