Problem Chat RMI

0

Mam następujący kod Serwera RMI:
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.util.LinkedList;
public class ChatServerImpl extends UnicastRemoteObject implements ChatServer {
private LinkedList<ChatClient> myclients;

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


public void broadcast(String s) throws RemoteException {
	// TODO Automatycznie generowany szkielet metody
	for (int i=0;i<myclients.size();i++){
		//System.out.println("adsads");
		System.out.println(s);
		//System.out.println(myclients.get(i));
		try{
		(myclients.get(i)).receive(s);
		}
		catch(Exception e){
			e.printStackTrace();
			
		}
	}
}

public void register(ChatClient c) throws RemoteException {
	// TODO Automatycznie generowany szkielet metody
	myclients.add(c);
}
public static void main(String[] args){
	//System.setProperty("java.security.policy", "client.policy");
	//System.setSecurityManager(new RMISecurityManager());
	try{
		
		Naming.rebind("ChatServer", new ChatServerImpl());
	}
	catch (Exception e){
		System.err.println("Problem....");
		
	}
	
}

}
z interfejsem
import java.rmi.*;
public interface ChatServer extends Remote

{
void register(ChatClient c) throws RemoteException;
void broadcast(String s) throws RemoteException;

}

Oraz Klienta:

import java.rmi.;
import java.rmi.server.
;
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("aa");
	System.out.println("Message:"+s);
	
}
public synchronized void run(){
	Scanner in=new Scanner(System.in);
	String msg="HALO";
	while (true){
		try{
			System.out.println("adsa");
			mycs.broadcast(msg);
			
		}
		catch (Exception e){
			System.err.println("Problem...");
			
		}
		
		
	}
	
	
}
public static void main(String[] args){
	System.setProperty("java.security.policy", "client.policy");
	System.setSecurityManager(new RMISecurityManager());
	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...");
		e.printStackTrace();
	}
	
}

}
import java.rmi.*;
public interface ChatClient extends Remote {
void receive(String s) throws RemoteException;

}

Problem jest taki,że Komunikat dochodzi do Serwera, a Serwer jakby nie mógł wywoływać metody receive zdalnego klienta, nie wiem czemu tak to się dzieje. Pomoże mi ktoś??
Potrzebuje rozwiązania na gwałt

0

Jakis wyjatek, blad, podpowiedz? Nie wierze ze nic sie nie dzieje i juz.

0

z tego co mi sie wydaje to musisz jeszcze wyeksportowac klienta do rejestru (bo z kodu wynika ze tez jest on serwerem metod) no i na jego rzecz wywolywac z serwera zdalna metode recive()

1 użytkowników online, w tym zalogowanych: 0, gości: 1