Lan Chatting system [closed]
- by jay prakash singh
Possible Duplicate:
LAN chating system or LAN chat server
displaying list of user to all the user window my code is
i m use RMI so this is the interface declaration
public void sendPublicMessage(String keyword, String username, String message) throws RemoteException;
public void sendPrivateMessage(String keyword, String username, String message) throws RemoteException;
public ArrayList getClientList() throws RemoteException;
public void connect(String username) throws RemoteException;
public void disconnect(String username) throws RemoteException;
}
chat Server
here connectedUser is the HasMap object
we use the follo0wing code for connection here ChatImpl is the stub
try
{
InetAddress Address = InetAddress.getLocalHost();
ChatImpl csi = new ChatImpl(this);
Naming.rebind("rmi://"+Address.getHostAddress()+":1099/ChatService", csi);
}
public ArrayList getClientList()
{
ArrayList myUser = new ArrayList();
Iterator i = connectedUser.keySet().iterator();
String user = null;
while(i.hasNext())
{
user = i.next().toString();
myUser.add(user);
}
return myUser;
}
public void addClient(Socket clientSocket) throws RemoteException
{
connectedUser.put(getUsername(), clientSocket);
sendPublicMessage(ONLINE, getUsername(), "CLIENT");
}
this is the client side code for array list
public void updateClient(ArrayList allClientList) throws RemoteException
{
listClient.clear();
int i = 0;
String username;
for(i=0; i<allClientList.size(); i++)
{
username = allClientList.get(i).toString();
listClient.addElement(username);
}
}