using the same appoach too.
here a snippets of what I do
for (Iterator<ClientConnectionHandler> iterator = list.iterator();
iterator.hasNext();) {
ClientConnectionHandler clientConnectionHandler =
iterator.next();
writeBuffer.put(sb.toString().getBytes());
writeBuffer.flip();
System.out.println("SENDING FEED TO CLIENT = [" +
sb.toString() + "]");
try {
if(clientConnectionHandler.getKey().isValid()){
clientConnectionHandler.getSelectorHandler().getAsyncQueueWriter().write(clientConnectionHandler.getKey(),
writeBuffer);
}
} catch (IOException e) {
e.printStackTrace();
// something obtain this error
// java.nio.channels.ClosedChannelException
// le client n'est pas connecte
clientConnectionHandler.close();
}
writeBuffer.rewind();
}
2008/8/18 Oleksiy Stashok <Oleksiy.Stashok_at_sun.com>
> Hello Ken,
>
> In grizzly we don't have any built-in mechanism for broadcasting...
> I think the way you used before is appropriate for Grizzly also.
>
> Thank you.
>
> WBR,
> Alexey.
>
>
> On Aug 18, 2008, at 5:47 , Ken--_at_newsgroupstats.hk wrote:
>
>
>> In the past with plain java.nio or old java.io. I used a HashMap to store
>> a
>> list of java.net.Socket/InputStream/OutputStream of logined client.
>>
>> Whenever I want to broadcast / send private message to client(s), I use:
>>
>> Vector vtClient = Clients.getAllClients(); // or
>> Clients.getClientById(id);
>> for() {
>> (Client)vtClient.elementAt(i).getOutputStream().write(messages);
>> }
>>
>> So, how to do it in grizzly? I know I can do it with my own method easily
>> but I want to know that best practice.
>>
>> Thanks and Regards,
>> Ken
>>
>>
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Best-Practice-to-broadcast---send-private-messages-to-client%28s%29-tp19025702p19025702.html
>> Sent from the Grizzly - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
>> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>
>