import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class HelloImpl extends UnicastRemoteObject implements Hello {
	public HelloImpl(String protocol, byte[] pattern) throws RemoteException {
		super(
			0,
			new XorClientSocketFactory(protocol, pattern),
			new XorServerSocketFactory(protocol, pattern));
	}

	public String sayHello() throws RemoteException {
		StringBuffer sb = new StringBuffer();
		for (int i=0;i<100;i++)
			sb.append("X");
		return sb.toString();
	}

	public static void main(String args[]) {

		System.setSecurityManager(new RMISecurityManager());
		byte[] aPattern = {(byte) 1011 };
		try {
			HelloImpl obj = new HelloImpl("xor", aPattern);
			Naming.rebind("rmi://53.16.71.55:1099/HelloServer", obj);
			System.out.println("HelloServer bound in registry");
		} catch (Exception e) {
			System.out.println("HelloImpl err: " + e.getMessage());
			e.printStackTrace();
		}
	}
}
