Package com.peterhi.net.remote

Source Code of com.peterhi.net.remote.Client

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);
  }
 
}
TOP

Related Classes of com.peterhi.net.remote.Client

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.