send message to specific clients using java
<p>How can i send message from server to any specific client. I have the concept of how to do it like i have to make a list of all the clients connected to server and then by iterating each client i can send message but i will be thankful if any one can help me by code.I have searched many codes but i didn't get any considerable help from them Code shouldn't be GUI based. Thanks in advance.Sorry for my bad English.
This is my code in which message is send to all clients but i want to send message to a client of my choice using clients ipaddress</p>

<pre><code>Map&lt;Integer, java.net.Socket&gt; clients = new HashMap&lt;Integer, java.net.Socket&gt; ();
socket = serverSocket.accept();

// Add the socket to a HashMap
clients.put(socket.getPort(), socket);
for (Iterator&lt;Integer&gt; iter = clients.keySet().iterator(); iter.hasNext(); )
{
    int key = iter.next();

    java.net.Socket client = clients.get(key);

    // Sending the response back to the client.
    // Note: Ideally you want all these in a try/catch/finally block
    OutputStream os = client.getOutputStream();
    OutputStreamWriter osw = new OutputStreamWriter(os);
    BufferedWriter bw = new BufferedWriter(osw);
    bw.write("Some message");
    bw.flush();
}
</code></pre>