UDP woes...

"Trustin Lee (이희승)" trustin at gmail.com
Thu Jan 14 19:41:27 EST 2010


fps wrote:
> 
> 
> 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?

ChannelPipelineCoverage for documentation purposes only.  In UDP, still
a single handler instance will handle all incoming packets to the same
port.  Read the Javadoc of ChannelPipelineCoverage.

>> 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...

MessageEvent e;
((InetSocketAddress) e.getRemoteAddress()).getPort()?

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

It's UDP - you should take care of ordering, reliability, connection
management all by yourself.

HTH,
Trustin

-- 
what we call human nature in actuality is human habit
http://gleamynode.net/


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20100115/990548b2/attachment.bin 


More information about the netty-users mailing list