package com.peterhi.net.remote;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import com.peterhi.net.remote.AboutMe.AboutMeListener;
import com.peterhi.net.rudp.RudpServer;
public class Client {
public static void main(String[] args) throws Exception {
work();
}
private static void work() throws Exception {
RudpServer client = new RudpServer();
final RmRegistry registry = new RmRegistry(client, 15000);
client.start(0);
SocketAddress address = new InetSocketAddress(
InetAddress.getLocalHost(), 22222);
final AboutMe am = registry.subscribe(address, AboutMe.class, "aboutMe");
System.out.println(am.toString());
System.out.println(am.myName());
System.out.println(am.address(AboutMe.CLIENT));
System.out.println(am.address(AboutMe.SERVER));
AboutMeListener listener = new AboutMeListener() {
@Override
public void callback(String message) {
System.out.println("Called back. " + message);
am.removeListener(this);
try {
registry.unregister(this);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("RETURNED!!!");
}
};
registry.register(AboutMeListener.class, listener);
am.addListener(listener);
}
}