CHAT PROGRAM USING JAPPLET.
My problem is that I have developed a chat program using RMI and Swings by defining a
ClientInterface which will be having setMessage(String s) method which will be called
by server,and ServerInterface which will be having three methods login(ClientInterface
client,String
name),logout(String str,String name),sendMessage(String name),and server program and a
client .
It is working properly when the client is a normal user(frame), But I�d like to have a
Client program if it is Japplet.I'am sending my problem in the attachment.
_____________________________________________________
Chat with your friends as soon as they come online. Get Rediff Bol at
http://bol.rediff.com
CHAT PROGRAM USING JAPPLET.
My problem is that I have developed a chat program using RMI and Swings by defining a
ClientInterface which will be having setMessage(String s) method which will be called
by server ,and ServerInterface which will be having three methods
login(ClientInterface client,String name),logout(String str,String
name),sendMessage(String name),and server program and a client . It is working
properly when the client is a normal user(frame), But I�d like to have a Client
program if it is Japplet.
My ClientInterface :
import java.io.*;
import java.rmi.*;
public interface ClientInterface extends Remote
{
public void setMessage(String message) throws RemoteException;
}
My ServerInterface :
import java.rmi.*;
public interface ServerInterface extends Remote
{
public void login(ClientInterface client,String name) throws
RemoteException;
public void sendMessage(String str,String name) throws
RemoteException;
public void logout(String name) throws RemoteException;
}
Server :
import java.rmi.server.*;
import java.rmi.*;
import java.io.*;
import java.util.*;
public class Server extends UnicastRemoteObject implements
ServerInterface
{
private Hashtable chatters=new Hashtable();
public Server() throws RemoteException {
super();
}
public void login(ClientInterface client,String name)throws
RemoteException
{
chatters.put(name,client);
System.out.println(name +" is logged in");
}
public void sendMessage(String message,String name)throws
RemoteException
{
Enumeration part=chatters.keys();
while(part.hasMoreElements())
{ String str=null;
try
{
str=(String)part.nextElement();
ClientInterface client=(ClientInterface)chatters.get(str);
client.setMessage(name+":"+ message);
} catch(Exception ex)
{
System.out.println("Error in sending message to "+str);
chatters.remove(str);
}
}
}
public void logout(String name)throws RemoteException
{ chatters.remove(name);
System.out.println(name+" : LoggedOut");
}
public static void main(String args[])
{
try
{
Server server=new Server();
Naming.rebind("Chat",server);
System.out.println("Chat server is ready");
} catch(Exception e)
{
System.out.println("error"+e);
}
}
}
------------