How to determine active socket connection count?

Frederic Bregier fredbregier at free.fr
Thu Jul 23 10:36:55 EDT 2009


Hi Neil,

What Trustin was saying could be written as you need to do something like
this in your handler (from SimpleChannelHandler for instance):

static DefaultChannelGroup allChannels  = new
DefaultChannelGroup("netty-receiver");

	void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) {
                  allChannels.add(e.getChannel);
        }

Such that each time a channel is newly connected, it includes itself in the
group allChannels.
Then in allChannels, you will have the current number of connections (+1 if
you add the parent channel as you show in your example below).
You don't have to remove them from the group since they will remove
themselves when they are closing.

Also, using such a group is useful when you want to shutdown the service
(see the manual of Netty for that).

HTH,
Frederic


neilson9 wrote:
> 
> Thanks trustin, my Server does something like,
> 
> DefaultChannelGroup allChannels  = new
> DefaultChannelGroup("netty-receiver");
> Channel bind = bootstrap.bind(new InetSocketAddress(endPoint.getPort()));
> allChannels.add(bind);
> 
> however allChannels.size() is always 1 -(when I have many active
> connections)...
> 
> Cheers Neil.
> 
> 
> On Thu, Jul 23, 2009 at 10:07 AM, Trustin Lee (via Nabble) <
> ml-user+57722-1440662075 at n2.nabble.com<ml-user%2B57722-1440662075 at n2.nabble.com>
>> wrote:
> 
>> Hi Neil,
>>
>> Create a ChannelGroup and add the Channels to it then you can get the
>> number of established channels.
>>
>> HTH,
>> Trustin
>>
>> On 07/23/2009 05:12 PM, neilson9 wrote:
>> > Hi,
>> > Im trying to determine the 'Established' socket connection/channel
>> count
>> a
>> > NioServerSocketChannel.
>> >
>> > Is there a way of doing this?
>> >
>> > I looked through the API but havent had any luck so far
>> >
>> > Cheers Neil.
>>
>> _______________________________________________
>> netty-users mailing list
>> netty-users at ...<http://n2.nabble.com/user/SendEmail.jtp?type=node&node=3308378&i=0>
>> https://lists.jboss.org/mailman/listinfo/netty-users
>> — Trustin Lee, http://gleamynode.net/
>>
>>
>> ------------------------------
>>  View message @
>> http://n2.nabble.com/How-to-determine-active-socket-connection-count--tp3308167p3308378.html
>> To unsubscribe from How to determine active socket connection count?,
>> click
>> here< (link removed) =>.
>>
>>
>>
> 
> 


-----
Hardware/Software Architect
-- 
View this message in context: http://n2.nabble.com/How-to-determine-active-socket-connection-count--tp3308167p3309952.html
Sent from the Netty User Group mailing list archive at Nabble.com.



More information about the netty-users mailing list