1

im trying to use websocketx server demo in netty 4.0alpha8.

When i save a registered channel to a static final DefaultChannelGroup, it's easy to write message to all channels whith: allChannels.write(message);

But i want to write message to a specified channel with channel id, i used this:

final static ChannelGroup allChannels = new DefaultChannelGroup("registeredChannel");

public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
        super.channelRegistered(ctx);
        allChannels.add(ctx.channel());
    }

And then i store channelID=channel.id(), try to write message to this channel with allChannels.find(channelID).write(message); but it does not work. How can I do this?

4

0 回答 0