I need some advice how to implement a netty server which gets data from some source(files for example) and then sends it as strings to all connected clients. I'd like to have class Server and invoke method broadcast on an object of this class. It should be used like this:
Server server = new Server();
String message;
while (true) {
message = getMessage();
server.broadcast(message);
}
I know that for this purpose I can use ChannelGroup however I don't know how to prevent channel write buffer from being exceeded (I don't know how to use channel.isWritable()).
ChannelGroup broadcast = new DefaultChannelGroup("broadcast");
...
public void broadcast(String message) {
for (Channel channel : broadcast) {
if (channel.isWritable())
channel.write(message);
}
}
Above solution is wrong because I want each message to be delivered to each client. I'd appreciate some advice how to solve my problem.