0
\$\begingroup\$

I am creating a simple 2d multiplayer game supported by the Netty library. The server is located on my local computer. I have a problem: why are some clients unable to connect? I tested on several computers from different places connected to different networks. Virtually always everything works fine. For some reason my friend is unable to connect. What could be the reason? Others connect without any problems. I would like to add that we have the same network operator. The problematic person is the only one who has a different operator. Could it have anything to do with it? I am new to the operation between the server and the client. Why does it work for some and not for others? What are the possible reasons? I would be very grateful for your help.

EDIT:

Server setup:

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

        try {
            ServerBootstrap bootstrap = new ServerBootstrap();
            bootstrap.group(bossGroup, workerGroup)
                    .channel(NioServerSocketChannel.class)
                    .childHandler(new ChannelInitializer<SocketChannel>() {
                        @Override
                        public void initChannel(SocketChannel socketChannel) {
                            ChannelPipeline pipeline = socketChannel.pipeline();
                            pipeline.addLast(new ObjectDecoder(Integer.MAX_VALUE, ClassResolvers.cacheDisabled(null)));
                            pipeline.addLast(new ObjectEncoder());
                            pipeline.addLast(new ServerHandler());
                        }
                    });

            ChannelFuture channelFuture = bootstrap.bind(8080).sync();

            channelFuture.channel().closeFuture().sync();
        } finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }

Client setup:

        EventLoopGroup group = new NioEventLoopGroup();

        try {
            Bootstrap bootstrap = new Bootstrap();
            bootstrap.group(group)
                    .channel(NioSocketChannel.class)
                    .handler(new ChannelInitializer<SocketChannel>() {
                        @Override
                        public void initChannel(SocketChannel socketChannel) {
                            ChannelPipeline pipeline = socketChannel.pipeline();
                            pipeline.addLast(new ObjectDecoder(Integer.MAX_VALUE, ClassResolvers.cacheDisabled(null)));
                            pipeline.addLast(new ObjectEncoder());
                            pipeline.addLast(new ClientHandler());
                        }
                    });

            ChannelFuture channelFuture = bootstrap.connect("<SERVER IPv4>", 8080).sync();

            channelFuture.channel().closeFuture().sync();
        } finally {
            group.shutdownGracefully();
        }
```
\$\endgroup\$
4
  • \$\begingroup\$ We'll need more details about how you implemented your networking. \$\endgroup\$
    – DMGregory
    Jun 1, 2022 at 14:07
  • \$\begingroup\$ I have attached a code to the edited post. \$\endgroup\$
    – Adixe
    Jun 1, 2022 at 14:39
  • \$\begingroup\$ Can your friend ping your local server? \$\endgroup\$
    – Mangata
    Jun 1, 2022 at 15:19
  • \$\begingroup\$ We tested using the ping command from CMD, but it was useless. It looks like the server doesn't exist. Constantly returning error about message: Connection timed out: no forther information. \$\endgroup\$
    – Adixe
    Jun 1, 2022 at 15:36

1 Answer 1

0
\$\begingroup\$

This doesn't seem to be related to game development. (maybe?) Before checking your game code, first make sure that the network connection is working. Based on the information you have, maybe you can do the following checks:

  1. Make sure the tool to check network connectivity (ping command) is working. Try ping the server with a device you can connect successfully, if that fails, the firewall may be blocking the pings. Configure the Windows firewall to allow pings (You mentioned CMD so I assume you are using windows system).

  2. If all devices can ping successfully, it is a problem with the game code. And If only some devices(your friend's) cannot ping successfully, it is a network problem.

  3. For a network problem, better answers can be found on other exchange sites. Here are just some preliminary guesses:

    I tested on several computers from different places connected to different networks.

    1. Just in case, How different are these places and networks? Maybe they are in the same lan and you are using the lan ip? You can check your public ip here.
    2. Did your network operator provide you with a public ip even? Is it dynamic?
    3. Are either network of yours regulated? Does opening port 8080 require filing in your area?
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .