how to write to channels periodically
Norman Maurer
norman.maurer at googlemail.com
Thu Sep 29 01:31:36 EDT 2011
Hi there,
using a ChannelGroup sounds like the right solution here. Just a minor
thing.....
You don't need to remove the Channel from the ChannelGroup by yourself
if you use DefaultChannelGroup as it does this already for you via a
ChannelListener.
See:
http://docs.jboss.org/netty/3.2/xref/org/jboss/netty/channel/group/DefaultChannelGroup.html
Bye,
Norman
2011/9/29 M4 <m4io at hotmail.com>:
> -----Original Message-----
> From: fwachs
> Sent: Thursday, August 25, 2011 05:57
> To: netty-users at lists.jboss.org
> Subject: RE: how to write to channels periodically
>
> Hi there, I tried to implement what you suggested but couldn't.
> Seems like I can't quite implement that. That server class does not have a
> getChannels method and I have no idea how to implement it.
>
> Anybody could help me out a bit with this? I'm new to this.
>
> Thank you very much.
>
> Regards,
> Federico
>
> --
> View this message in context:
> http://netty-forums-and-mailing-lists.685743.n2.nabble.com/how-to-write-to-channels-periodically-tp6548832p6722253.html
> Sent from the Netty User Group mailing list archive at Nabble.com.
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>
>
> public class DiscardServerHandler extends SimpleChannelHandler {
>
> static final ChannelGroup channels = new DefaultChannelGroup();
>
>
> public ChannelGroup getChannels() {
> return channels;
> }
>
> public void channelConnected(ChannelHandlerContext ctx,
> ChannelStateEvent e) {
> log("channelConnected", "");
> Channel ch = e.getChannel();
> channels.add(ch);
> }
>
> @Override
> public void channelDisconnected(ChannelHandlerContext ctx,
> ChannelStateEvent e) {
> if (channels.contains(e.getChannel() )) {
> channels.remove(e.getChannel());
> }
> log("channelDisconnected", "");
> }
>
>
> }
>
>
> In short ; I added a public method to the class DiscardServerHandler
> 'getChannels'. That method returns all channels of type ChannelGroup .
> I add and remove a new channel manually after a user connects. Maybe this is
> not efficient but it works for me in a simple test environment.
>
> Regards,
> Walter
>
> _______________________________________________
> 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