hello guys, ive been searching for ages on how to disconnect a client whether the request is from client or server but i cant find one. I thought the Naming.unbind() would do the trick but its not. anyway, this is my server code since I want to have my server a "kick" functionality to disconnect my clients..
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;
public class Server extends UnicastRemoteObject implements Chat{
Vector<Notify> clients = new Vector<Notify>();
public Server() throws RemoteException{
super();
}
public static void main(String args[]) throws Exception{
Server server = new Server();
String bind = "rmi://localhost:1099/DICMTRMI";
System.out.println("Server started and binded to: " + bind);
System.out.println("Waiting for client connections...");
Naming.rebind(bind, server);
}
public void join(Notify n) throws RemoteException {
clients.add(n);
for(Iterator i = clients.iterator(); i.hasNext();){
Notify notify = (Notify) i.next();
notify.notifyJoine(n.getName());
}
System.out.println(n.getName() + " has joined the server.\n");
}
public void talk(Notify n, String message) throws RemoteException {
for(Notify not : clients){
not.notifySend(n.getName(), message);
}
System.out.println(n.getName() + ": " + message + "\n");
}
public void leave(Notify n) throws RemoteException {
clients.remove(n);
for(Iterator i = clients.iterator(); i.hasNext();){
Notify notify = (Notify) i.next();
notify.notifyLeave(n.getName());
}
System.out.println(n.getName() + ": has leaved the server.\n");
lefts();
}
private void lefts() throws RemoteException{
System.out.println("Clients left:\n");
for(Notify not : clients){
System.out.println(not.getName() + ",");
}
System.out.println("\n");
}
}
Please inform me of what should I do.