我这个是监听send按钮向所有客户端发送消息,请问怎样才能向指定客户端发送呢
public void actionPerformed(ActionEvent e) {
String data = "";
if ("sendMsg".equals(e.getActionCommand())) {
if ((data = this.input.getText()) != null) {
this.appendMsg("服务器-->" + data);
Set keset = this.clients.keySet();
java.util.Iterator iter = keset.iterator();
while (iter.hasNext()) {
int key = iter.next();
Socket socket = clients.get(key);
try {
Writer writer = new OutputStreamWriter(
socket.getOutputStream());
writer.write(ByteUtils.hexStr2Str(data.replace(" ", "")));
logger.debug(data);
writer.flush();
} catch (SocketException e1) {
} catch (IOException e1) {
e1.printStackTrace();
}
}
this.input.setText("");
}
}
}