PDA

Click to See Complete Forum and Search --> : ComputerJy, I need your expert help on my small client/server app


Pouncer
Oct 16th, 2007, 12:14 PM
--------------------

ComputerJy
Oct 16th, 2007, 11:53 PM
I'm not sure if it will work but try this:
public static void sendMessageToClients(Selector selector, SelectionKey key, SelectionKey serverKey, String message) {
Set keys = selector.*******eys[b]();

for (Iterator i = keys.iterator(); i.hasNext();) {
SelectionKey sel_key = (SelectionKey) i.next();

try {
// Skip if key is associated with server-socket channel.
if (sel_key.equals(serverKey)) {
continue;
}
// Otherwise get the socket-channel associated with the key.
SocketChannel client = (SocketChannel) sel_key.channel();
client.configureBlocking(false);
if (!client.isConnected()) {
client.connect(new InetSocketAddress(PORT));
while (client.isConnectionPending()) {
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
}
}
}
I only added the last 6 lines just to make sure the client is connected to the server.