UDP woes...

fps fred.soulier.ml at gmail.com
Thu Jan 14 18:49:09 EST 2010




fps wrote:
> 
> Hi
> 
> Ok I've got the following class which creates the ConnectionlessBootstrap
> for UDP with a very simple pipeline.
> 
> I'm running a test in the same where I bootstrap the UDP server then
> starts to UDP clients.
> My ConnectionHandler has a @ChannelPipelineCoverage("one") yet both
> clients end up using the same channel handler context which creates a mess
> when processing the messages... 
> I can see client #1 127.0.0.1:54634 and client #2 127.0.0.1:55789
> 
> Am I missing something here?
> 
> 
> public class Udp implements Pipeline, ChannelPipelineFactory
> {
>   private ConnectionlessBootstrap bootstrap;
>   private Channel channel;
> 
>   public Udp(int port)
>   {
>     bootstrap = new ConnectionlessBootstrap(new
>            NioDatagramChannelFactory(Executors.newCachedThreadPool(),
>            Runtime.getRuntime().availableProcessors()));
>     bootstrap.setPipelineFactory(this);
>     bootstrap.setOption("receiveBufferSizePredictorFactory",
>           new FixedReceiveBufferSizePredictorFactory(1400));
>     bootstrap.setOption("child.broadcast", false);
>     channel = (DatagramChannel)bootstrap.bind(new
> InetSocketAddress(port));
>   }
> 
>   public Bootstrap getBootstrap()
>   {
>     return bootstrap;
>   }
> 
>   public Channel getChannel()
>   {
>     return channel;
>   }
> 
>   public ChannelPipeline getPipeline()
>     throws Exception
>   {
>     ChannelPipeline pipeline = Channels.pipeline();
>     pipeline.addLast("connection", new ConnectionHandler());
>     return pipeline;
>   }
> }
> 
> Thx
> Fred
> 

Ok re-reading some other posts:

"Again, TCP uses one server socket plus many accepted sockets, but UDP
uses only one server socket to communicate with multiple peers.

In MINA, I did some sort of emulation similar to your suggestion; MINA
created multiple virtual session objects for each remote address.
However, there is no such virtual sessions in Netty anymore - one Netty
Channel is supposed to handle all messages from all remote addresses."

So for UDP the same channel deals will all messages from all remote
addresses. So if all clients are coming from the same address (say
localhost) how can I differentiate the clients?
The only parameter which is different is the client remote port which
doesn't seem to be accessible...

Is that the case that all clients sending UDP messages should identify
themselves uniquely with some sort of id in each message?

Thx
Fred

-- 
View this message in context: http://n2.nabble.com/UDP-woes-tp4394311p4396181.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list