Beispiel #1
0
  public static void main(String[] args) throws Exception {

    int port = 0;
    String host = "";
    String message = "";

    /*
     * Parse port argument.
     */
    if (args.length > 2) {
      host = args[0];

      try {
        port = Integer.parseInt(args[1]);
        if (port == 0) {
          goodbye("nonzero port argument required", null);
        }

      } catch (NumberFormatException e) {
        goodbye("malformed port argument", e);
      }
      message = args[2];

    } else {
      usage();
    }

    /*
     * Lookup service by name in the registry on the specified host and
     * port.
     */
    Registry registry = LocateRegistry.getRegistry(host, port);
    ServiceInterface proxy = (ServiceInterface) registry.lookup("ServiceInterface");

    /*
     * Invoke the 'sendMessage' method on the service passing the
     * specified message.
     */
    System.out.println("sending message: " + message);
    System.out.println("received message from proxy: " + proxy.sendMessage(message));

    System.out.println("done.");
  }