how to write to channels periodically

M4 m4io at hotmail.com
Wed Sep 28 23:56:57 EDT 2011


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



More information about the netty-users mailing list