OioDatagramChannelFactory for client and server?

Trustin Lee tlee at redhat.com
Mon Apr 20 22:59:37 EDT 2009


Now I see your point. :)

ServerBootstrap is only useful for a server-side transport that
creates a new child channel from a bound server channel by accepting
an incoming connection attempt.

A datagram socket works very differently from that - a single datagram
channel accepts all packets from any remote address and therefore no
child channel is created (i.e. one channel handles all clients).
Consequently, DatagramChannel does not implement ServerChannel and
neither does OioDatagramFactory.

You can also convert a bound datagram channel into a connected
datagram channel simply by calling Channel.connect(), which means a
datagram channel can be either client-side and server-side channel at
your will.  Hence, it's not possible to distinguish server-side
datagram channel factory from client-side datagram channel factory
because they creates the same type of channel.  Only what you do to
the new channel determines if it becomes a client-side channel or a
server-side channel.

HTH,

— Trustin Lee, http://gleamynode.net/

On Mon, Apr 20, 2009 at 8:09 PM, hezjing <hezjing at gmail.com> wrote:
> Hi Trustin
> Yes, I have read the QOTM example and I have tried that with Netty 3.1
> BETA1.
> I was thinking that ServerBootstrap generic, and it is applicable for
> all ChannelFactory.
> In this case, I think the  ServerBootstrap is applicable with all
> ChannelFactory except the DatagramChannelFactory?
>
> I think that is something worth to explain in the Javadoc
> of ServerBootstrap(ChannelFactory).
>
> Thank you!
>
> On Mon, Apr 20, 2009 at 6:31 PM, Trustin Lee <tlee at redhat.com> wrote:
>>
>> You do not need to use ServerBootstrap for the UDP transport.  Could
>> you please read the QOTM example?
>>
>> — Trustin Lee, http://gleamynode.net/
>>
>> On Mon, Apr 20, 2009 at 6:31 PM, hezjing <hezjing at gmail.com> wrote:
>> > Hi
>> > I'm trying to create a UDP server with Netty 3.1 BETA2, here is the code
>> > snippet:
>> >         ChannelFactory factory = new
>> > OioDatagramChannelFactory(Executors.newCachedThreadPool());
>> >         ServerBootstrap bootstrap = new ServerBootstrap(factory);
>> >         ChannelPipeline pipeline = bootstrap.getPipeline();
>> >         pipeline.addLast("logger", new LoggingHandler(true));
>> >         ...
>> >         Channel channel = bootstrap.bind(new
>> > InetSocketAddress(listenPort));
>> >
>> > When run, it throws the following exception:
>> > Exception in thread "main" java.lang.IllegalArgumentException: factory
>> > must
>> > be a ServerChannelFactory:
>> > class org.jboss.netty.channel.socket.oio.OioDatagramChannelFactory
>> >     at
>> >
>> > org.jboss.netty.bootstrap.ServerBootstrap.setFactory(ServerBootstrap.java:183)
>> >     at org.jboss.netty.bootstrap.Bootstrap.<init>(Bootstrap.java:73)
>> >     at
>> >
>> > org.jboss.netty.bootstrap.ServerBootstrap.<init>(ServerBootstrap.java:174)
>> >
>> > Do you have any idea of what could be the reason?
>> >
>> > On Wed, Apr 8, 2009 at 4:50 PM, Trustin Lee <tlee at redhat.com> wrote:
>> >>
>> >> On Wed, Apr 8, 2009 at 5:49 PM, Trustin Lee <tlee at redhat.com> wrote:
>> >> > On Sat, Apr 4, 2009 at 5:06 PM, hezjing <hezjing at gmail.com> wrote:
>> >> >> Hi
>> >> >> The Javadoc explains that OioDatagramChannelFactory is to create
>> >> >> a blocking
>> >> >> I/O based UDP client.
>> >> >>
>> >> >> What should we use to create a UDP server?
>> >> >
>> >> > Actually, you can create a UDP client using
>> >> > OioDatagramChannelFactory.
>> >> >  It was a documentation mistake.  Please refer to the QOTM server
>> >> > example.
>> >>
>> >> Oops.  Actually, you can create both UDP client and server using
>> >> OioDatagramChannelFactory.  It was a documentation mistake.  Please
>> >> refer to the QOTM server example.
>> >>
>> >> _______________________________________________
>> >> netty-users mailing list
>> >> netty-users at lists.jboss.org
>> >> https://lists.jboss.org/mailman/listinfo/netty-users
>> >
>> >
>> >
>> > --
>> >
>> > Hez
>> >
>> > _______________________________________________
>> > netty-users mailing list
>> > netty-users at lists.jboss.org
>> > https://lists.jboss.org/mailman/listinfo/netty-users
>> >
>> >
>>
>> _______________________________________________
>> netty-users mailing list
>> netty-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/netty-users
>
>
>
> --
>
> Hez
>
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>
>




More information about the netty-users mailing list