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 7854683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:08:45+00:00 2026-06-02T20:08:45+00:00

We’ve got a server which is already implemented in TCP/IP but we now have

  • 0

We’ve got a server which is already implemented in TCP/IP but we now have a requirement for the protocol to support UDP as well.

Each UDP datagram sent contains everything I need to decode so it is a very simple reply and response system with data in the datagram separated by line breaks.

The code for the bootstrap when the server is started is shown below:

    //SETUP UDP SERVER
    DatagramChannelFactory udpFactory = new NioDatagramChannelFactory(Executors.newCachedThreadPool());

    ConnectionlessBootstrap udpBootstrap = new ConnectionlessBootstrap(udpFactory);

    udpBootstrap.setOption("sendBufferSize", 65536);
    udpBootstrap.setOption("receiveBufferSize", 65536);
    udpBootstrap.setOption("receiveBufferSizePredictorFactory", new AdaptiveReceiveBufferSizePredictorFactory());

    udpBootstrap.setOption("broadcast", "true");
    udpBootstrap.setPipelineFactory(new ServerPipeLineFactoryUDP());
    udpBootstrap.bind(new InetSocketAddress(hostIp, 4000)); 

The Pipeline code is:

class ServerPipeLineFactoryUDP implements ChannelPipelineFactory
{

    private final static ExecutionHandler EXECUTION_HANDLER = new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(ScorpionFMS.THREAD_POOL_COUNT, 0, 0));

    public ServerPipeLineFactoryUDP()
    {

    }

    @Override
    public ChannelPipeline getPipeline() throws Exception
    {

    ChannelPipeline pipeline = pipeline();
    pipeline.addLast("debugup", new DebugUpstreamHandler("UDP"));
    pipeline.addLast("debugdown", new DebugDownstreamHandler("UDP"));

    pipeline.addLast("framer", new DelimiterBasedFrameDecoder(256, Delimiters.lineDelimiter()));

    pipeline.addLast("decoder", new UDPRequestDecoder(true));
    pipeline.addLast("encoder", new StringEncoder());
    pipeline.addLast("executor", EXECUTION_HANDLER);
    pipeline.addLast("handler", new UDPRequestHandler(

    return pipeline;
    }
}

The problem im having is each datagram is using the same instance of this pipeline (i hoped each datagram would use a new instance of the pipeline), so all the state i store while processing the contents of a datagram is saved and the next datagram uses it as well,( whereas for TCP each connection would have its own channel and therefore its own instance of the pipeline and its own state)

I know this is the expected behaviour from reading the documentation but is there anyway to force netty to recreate the pipeline for each datagram? Or am i going about this the completely wrong way?

To put it succinctly, i want each datagram to have a new instance of the pipeline (the same as tcp)

  • 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-02T20:08:47+00:00Added an answer on June 2, 2026 at 8:08 pm

    Like I said in IRC, I think that could do what you want or at least give you some idea.

    public class Example {
    
        public static void main(String[] args) {
            final ChannelPipelineHandlerImpl perDatagramFactory = new ChannelPipelineHandlerImpl();
    
            DatagramChannelFactory udpFactory = new NioDatagramChannelFactory(Executors.newCachedThreadPool());
    
            ConnectionlessBootstrap udpBootstrap = new ConnectionlessBootstrap(udpFactory);
    
            udpBootstrap.setPipelineFactory(new ChannelPipelineFactory() {
    
                public ChannelPipeline getPipeline() throws Exception {
                    return Channels.pipeline(new DistinctChannelPipelineHandler(perDatagramFactory));
                }
            });
    
        }
    
        private static final class DistinctChannelPipelineHandler implements ChannelDownstreamHandler, ChannelUpstreamHandler {
            private ChannelPipelineFactory factory;
    
            public DistinctChannelPipelineHandler(ChannelPipelineFactory factory) {
                this.factory = factory;
            }
    
            public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
                ChannelPipeline pipeline = factory.getPipeline();
                pipeline.attach(ctx.getChannel(), ctx.getPipeline().getSink());
                pipeline.sendUpstream(e);
    
                ctx.sendUpstream(e);
    
            }
    
            public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
                ChannelPipeline pipeline = factory.getPipeline();
                pipeline.attach(ctx.getChannel(), ctx.getPipeline().getSink());
                pipeline.sendDownstream(e);
    
                ctx.sendDownstream(e);
            }
    
        }
    
        private static final class ChannelPipelineHandlerImpl implements ChannelPipelineFactory {
    
            public ChannelPipeline getPipeline() throws Exception {
                // Add your handlers here
                return Channels.pipeline();
            }
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.