Results 1 to 2 of 2

Thread: ComputerJy, I need your expert help on my small client/server app

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    ComputerJy, I need your expert help on my small client/server app

    --------------------
    Last edited by Pouncer; Oct 18th, 2007 at 05:42 PM.

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: ComputerJy, I need your expert help on my small client/server app

    I'm not sure if it will work but try this:
    Code:
        public static void sendMessageToClients(Selector selector, SelectionKey key, SelectionKey serverKey, String message) {
            Set keys = selector[b].*******eys();
    
            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.
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width