Send message to all connected Clients

"Trustin Lee (이희승)" trustin at gmail.com
Mon Dec 28 20:38:04 EST 2009


Sorry for the late response.

Stephen Pape wrote:
> 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. 

When you call an operation on ChannelGroup, a ChannelGroupFuture is
returned.  You can iterate on the ChannelFuture instances by calling
ChannelGroupFuture.iterator().

Currently, the iteration order is not deterministic since HashMap is
used internally.  Perhaps we could replace it with LinkedHashMap?

HTH,
Trustin

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20091229/36262018/attachment.bin 


More information about the netty-users mailing list