source code for chatroom application

February 28, 2010 at 23:07:44
Specs: Windows XP
hi buddy.. i need the source code for chat room application in java using rmi.. colud provide me that for my college assignment...

See More: source code for chatroom application

Report •


#1
March 1, 2010 at 10:54:45
I think you will find that the plan is that you write it yourself. That's what collage assignments are for, to prove that you can do it and not just plagiarise someone else's work.

Stuart


Report •

#2
March 1, 2010 at 21:34:49
Hi vivek..

here is ur code.. but try re-modifying it ..

import java.rmi.*;

public interface ChatServer extends Remote
{
void register(ChatClient c) throws RemoteException;
void broadcast(String s) throws RemoteException;
}

import java.rmi.*;

public interface ChatClient extends Remote
{
void receive (String s) throws RemoteException;
}

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.util.Scanner;

public class ChatClientImpl extends UnicastRemoteObject implements ChatClient, Runnable
{
private ChatServer mycs;
public ChatClientImpl (ChatServer cs) throws RemoteException
{
mycs=cs;
mycs.register(this);
}

public synchronized void receive (String s) throws RemoteException
{
System.out.println("Message :"+s);
}
public void run ()
{
Scanner in=new Scanner(System.in);
String msg;

while(true)
{
try
{
msg=in.nextLine();
mycs.broadcast(msg);
}
catch(Exception e)
{
System.err.println("problem");
}
}
}

public static void main (String[] args)
{
String url = "rmi://localhost/ChatServer";
try
{
ChatServer cs= (ChatServer) Naming.lookup(url);
new Thread(new ChatClientImpl(cs)).start();
}
catch (Exception e)
{
System.err.println("Problem") ;
}
}
}

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.util.LinkedList;
import java.util.Scanner;

public class ChatServerImpl extends UnicastRemoteObject implements ChatServer
{
private LinkedList "<"ChatClient">" myclients;

public ChatServerImpl() throws RemoteException
{
myclients = new LinkedList();
}

public synchronized void register (ChatClient c) throws RemoteException
{
myclient.add(c);
}

public synchronized void broadcast (String s) throws RemoteException
{
for(int i=0;i< myclient.size();i++)
{
myclient.get(i).receive(s);
}
}

public static void main (String[] args)
{
try
{
Naming.rebind("ChatServer", new ChatServerImpl());
}
catch(Exception e)
{
System.err.println("Problem") ;
}
}
}

grant
{
permission java.security.AllPermission;
};


Report •

Related Solutions


Ask Question