es facil solo tienes que crear un obj usuario por cada conexion entrante y comunicarte con el enviandole algun command/msg.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Hashtable;
/**
* @Autor Leyer
* @see GlassFish Tools Bundle For Eclipse
*
* Servidor simple para multiples conexiones
*/
interface config{
public static final int _port = 8081;
public static final int _backlog = 500;
public static final String _host
= "localhost"; }
{
private class user
extends Thread{ private boolean connected = false;
private int nro = 0;
private String username
= null; public user
(Socket socket,
int nro
){ this.socket = socket;
try {
printWriter
= new PrintWriter(this.
socket.
getOutputStream()); connected = true;
username = this.socket.getLocalAddress().getHostAddress();
this.nro = nro;
e.printStackTrace();
}
}
printWriter.println(msg);
}
public boolean isActive() {
return connected;
}
public void setActive(boolean active) {
this.connected = active;
}
@Override
public void run() {
while(connected){
try {
if(reader.ready()){
String msg
= reader.
readLine(); System.
out.
println(" User:"+nro
+ "+"+username
+"-> "+msg
); if(msg.equalsIgnoreCase("disconnected")){
handler.remove(username);
}
}
e.printStackTrace();
}
}
}}
boolean init = true;
private Hashtable
< String, user
> handler
= new Hashtable
<String, user
>(); int nro = 0;
@Override public void run() {
while(init){
try {socket = accept();
System.
out.
println("New User: "+socket.
getLocalAddress().
getHostAddress()); handler.put(socket.getLocalAddress().getHostAddress(), new user(socket,nro));
handler.get(socket.getLocalAddress().getHostAddress()).writer("true");
nro ++;
e.printStackTrace();
}
}
}
public boolean isInit() {
return init;
}
public void setInit(boolean init) {
this.init = init;
}
public server
(int port,
int backlog,
InetAddress bindAddr
) super(port, backlog, bindAddr);
System.
out.
println("---------------------------------------"); System.
out.
println("Server is OK"); System.
out.
println("---------------------------------------"); }
/**
* @param args
* @throws IOException
* @throws UnknownHostException
*/
new server(config._port,
config._backlog,
}
}
Saludos