Send message to all connected Clients

Stephen Pape Stephen.Pape.ctr at RL.af.mil
Wed Dec 16 09:33:19 EST 2009


I haven't had time to really look in to it, but it's definitely important to
us. We'll often be sending the exact same serialized object to a list of
clients simultaneously.

The workaround I was thinking about would be to create a downstream handler
that could be added to the pipeline of any type of channel after
serialization took place. This handler would have methods to add and remove
the channels to be written to. Where we needed multiplexing, our code could
add this handler to the pipeline and configure it.

The handler itself would simply not pass the message downstream, removing it
from the pipeline and sending it off to a ChannelGroup, which would contain
some simple channels capable of writing ChannelBuffers and maybe enabling
compression/SSL individually. 

One problem I'm not sure about yet is how I'd return the ChannelFuture from
the ChannelGroup to whatever calls the initial write. 

-Stephen


Trustin Lee wrote:
> 
> Hi Stephen et al,
> 
> On 2009/12/10 5:29 am, Stephen Pape wrote:
>> 
>> Hi,
>> 
>> I've been looking into this same problem. It'd seem you'd have to
>> serialize
>> the object ahead of time, outside of Netty, into a ChannelBuffer. From
>> there
>> you can call ChannelGroup.write() and just send the ChannelBuffer.
> 
> Yes.  Also, you can reuse your existing Netty encoder to serialize the
> object using the EncoderEmbedder.
> 
>> This avoids the serialization overhead, but it doesn't fit well into my
>> design. I'd like to reuse the single channels and somehow add a
>> multiplexer
>> into the pipeline. Maybe intercepting the handleUpstream call and taking
>> the
>> ChannelBuffer, then passing it off to the ChannelGroup? I'm not sure how
>> this'd work with ChannelFuture though.
> 
> Could you elaborate your idea with me?  Some pseudo code would suffice.
> 
> (perhaps you meant handleDownstream instead of handleUpstream?)
> 
> Thanks,
> Trustin
> 
>> Sergey S wrote:
>>>
>>> Hi
>>>
>>> there is perfomance issue with ChannelGroup.write method. Written object
>>> will be serialized N times for ChannelGroup of N channels. Do you know
>>> how
>>> to avoid this serialization overhead?
>>>
>>>
>>> Sebastian Andersson wrote:
>>>>
>>>> On Tue, Oct 13, 2009 at 19:40, nettyuser <nettyuser at mailinator.com>
>>>> wrote:
>>>>> I would like to send some messages from the server to all the
>>>>> connected
>>>>> clients. Can someone please let me  know the proper way to do this
>>>>> using
>>>>> Netty API.
>>>>
>>>> Store the Channels in a ChannelGroup when they connect and then send
>>>> the message to the ChannelGroup.
>>>> Its used in one of the examples, the chat-server I believe.
>>>>
>>>> /Sebastian
>>>>
>>>>>
>>>>> Thanks.
>>>>>
>>>>> --
>>>>> View this message in context:
>>>>> http://n2.nabble.com/Send-message-to-all-connected-Clients-tp3817609p3817609.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
>>>>>
>>>>
>>>>
>>>>
>>>> -- 
>>>> One laptop per child project: http://laptop.org/
>>>>
>>>> _______________________________________________
>>>> 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
> 
> 

-- 
View this message in context: http://n2.nabble.com/Send-message-to-all-connected-Clients-tp3817609p4175786.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list