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

  • SEARCH
  • Home
  • 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 7921283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:31:35+00:00 2026-06-03T16:31:35+00:00

I have a TCP based Netty application with multiple clients that need to communicate

  • 0

I have a TCP based Netty application with multiple clients that need to communicate with each other. I store all of the Channel references in a ChannelGroup.

While I know that I can write to every client in a ChannelGroup by calling ChannelGroup.write, but what would be an efficient way to write to all but one of these channels, for example:

‘A’,’B’,’C’ are in a Channel Group together and ‘A’ needs to send to ‘B’ and ‘C’, ‘B’ needs to send to ‘A’ and ‘C’, etc. What would be the best way to do this? Here are some options I thought of but some feedback would be appreciated:

  1. Just iterate through the Group and write to the channels individually (don’t use ChannelGroup.write in this case)

  2. Repeatedly “remake/clone” the ChannelGroup so it contains only the channels to write to. I would then call ChannelGroup.write on the modified group, then restore the group to the full group.

  3. Write to all channels but implement some Handler logic to discard (either on Encode or Downstream Handler) and not write the message if it is from the excluded channel.

As far as design trade offs are concerned, messages are sent as rapidly as possible, ChannelGroups are relatively small <20 channels and messages are about 1kb in size each (500 bytes – 2 kb). Also, there is a scenario under which many of the connections are on the same host as the Server if different logic works better for localhost feedback on this would be greatly appreciated.

Thanks so much for any help!

  • 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-06-03T16:31:37+00:00Added an answer on June 3, 2026 at 4:31 pm

    I would not do #2. So far as I know, there is no inherent performance benefit to writing to a channel group. If you look at the code for DefaultChannelGroup, it simply iterates through the registered channels, issues the write and collects the futures:

    public ChannelGroupFuture write(Object message) {
             Map<Integer, ChannelFuture> futures =
                 new LinkedHashMap<Integer, ChannelFuture>(size());
             if (message instanceof ChannelBuffer) {
                 ChannelBuffer buf = (ChannelBuffer) message;
                 for (Channel c: nonServerChannels.values()) {
                     futures.put(c.getId(), c.write(buf.duplicate()));
                 }
             } else {
                 for (Channel c: nonServerChannels.values()) {
                     futures.put(c.getId(), c.write(message));
                 }
             }
             return new DefaultChannelGroupFuture(this, futures);
         }
    

    …. although you do get the benefit of a multiplexed future, which if you care about the completion callbacks, is useful.

    I would not do #3 either since you are just giving the downstream handlers more work to do, discarding data that you went to all the bother to write in the first place.

    So I would either:

    1. Implement Option #1
    2. Extend DefaultChannelGroup and add a write method that is clever enough to skip the channel in question. You would probably have to provide a bit more meta-data when you add the channels to the group.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been developing my first TCP/Socket based application with Apache Mina, it looks
I need to write a daemon that supposed to have one TCP socket and
I have three TCP servers I need to connect to, each with different protocols,
I have an application that receives relatively sparse traffic over TCP with no application-level
We have two machines which need to communicate: a Linux based gateway, and a
I have a java-based server that allows client applications to connect via other programming
I have an array of float that I need to send over TCP/IP, the
I have a Python application which opens a simple TCP socket to communicate with
I have a small utility application that handles sockets, both TCP and UDP. Occasionally,
I have two TCP-server apps that are based on the same code, but for

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.