Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6166985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:26:02+00:00 2026-05-23T22:26:02+00:00

I`m trying to test netty, but when i creating a multiple clients to connect

  • 0

I`m trying to test netty, but when i creating a multiple clients to connect to server, some of client just froze and never finish.
Here my code( basically i used code from her https://github.com/brunodecarvalho/netty-tutorials and just modify it to use a several clients):


 for (int i = numthr; i > 0; i--) {
            Runnable runner = new Runnable() {
                public void run() {
                    final Client client = new Client("localhost", 10400, nummes, 0);
                    if (!client.start()) {
                        System.exit(-1);
                        return;
                    }
                    client.flood();
                    Runtime.getRuntime().addShutdownHook(new Thread() {
                        @Override
                        public void run() {
                            client.stop();
                        }
                    });
                }
            };
            executor.execute(runner);
        }

    public void messageReceived(Envelope message) {

        if (this.received.incrementAndGet() == this.messages) {

            System.out.println(nmb.incrementAndGet());


        }
    }

     public boolean start() {

        // For production scenarios, use limited sized thread pools
        this.clientFactory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(),
                                                               Executors.newCachedThreadPool(),1);
        this.channelGroup = new DefaultChannelGroup(this + "-channelGroup");
        this.handler = new ClientHandler(this, this.channelGroup);
        ChannelPipelineFactory pipelineFactory = new ChannelPipelineFactory() {

            @Override
            public ChannelPipeline getPipeline() throws Exception {
                ChannelPipeline pipeline = Channels.pipeline();
                pipeline.addLast("encoder", new Encoder());
                pipeline.addLast("decoder", new Decoder());
                pipeline.addLast("handler", handler);
                return pipeline;
            }
        };

        ClientBootstrap bootstrap = new ClientBootstrap(this.clientFactory);
        bootstrap.setOption("reuseAddress", true);
        bootstrap.setOption("tcpNoDelay", true);
        bootstrap.setOption("keepAlive", true);
        bootstrap.setPipelineFactory(pipelineFactory);


        boolean connected = bootstrap.connect(new InetSocketAddress(host, port)).awaitUninterruptibly().isSuccess();
        if (!connected) {
            this.stop();
        }

        return connected;
    }

       this.serverFactory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
                                                               Executors.newCachedThreadPool());
        this.channelGroup = new DefaultChannelGroup(this + "-channelGroup");
        ExecutionHandler executionHandler = new ExecutionHandler(
                new MemoryAwareThreadPoolExecutor(270, 1048576, 1048576));

        ServerBootstrap bootstrap = new ServerBootstrap(this.serverFactory);
        bootstrap.setPipelineFactory(
                new DatabaseGatewayPipelineFactory(executionHandler));
        bootstrap.setOption("reuseAddress", true);
        bootstrap.setOption("child.tcpNoDelay", true);
        bootstrap.setOption("child.keepAlive", true);
        bootstrap.setOption("child.connectTimeoutMillis", 10000);

        Channel channel = bootstrap.bind(new InetSocketAddress(this.host, this.port));
        if (!channel.isBound()) {
            this.stop();
            return false;
        }

        this.channelGroup.add(channel);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:26:03+00:00Added an answer on May 23, 2026 at 10:26 pm

    The code is making new thread for Client each time, with same port number. This can create problems, because multiple threads are processing messages on the same port.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just trying to test for equality in this piece of code, but getting a
I'm trying to test a client/server application, and using Maven to handle the build/test/deploy.
I trying to test an AccountController that uses DotNetOpenAuth but I am running into
I'm trying to test a method I have in my application, but I don't
I am trying to test the logic from some existing classes. It is not
I am trying to test on a private development server, and I can't use
I'm trying to test my Session Beans with JUnit, but I can't. I've tried
I'm trying to test this out on my site but it doesn't quite work
When trying to test across multiple versions of Internet Explorer (6, 7, 8) I
I'm trying to test out pyssh, but I'm having trouble importing it. I'm new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.