by
3
6
294k
1
Top 1% !
Popular
Pearl of Wisdom
Tagged
Specified
OpenSource
Popularity: 3907th place

Published on:

ClassNameClient
InputName0args
InputType0String[]
Languagejava
LicenseMIT_X11
MethodNamemain
OutputTypevoid

Simple RMI Java client

This is a simple RMI client implementation.
Here the client program obtains a stub for the registry on the server's host, then looks up the remote object's stub by name in the registry. Finally invokes the sayHello method on the remote object using the stub.
Here the client invokes the method exposes by Hello remote interface.

Note that if no hostname is specified, then null is used as the hostname indicating that the local host address should be used.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/32348/Simple-RMI-Java-client?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
package example.hello; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; public class Client { private Client() {} public static void main(String[] args) { String host = (args.length < 1) ? null : args[0]; try { Registry registry = LocateRegistry.getRegistry(host); Hello stub = (Hello) registry.lookup("Hello"); String response = stub.sayHello(); System.out.println("response: " + response); } catch (Exception e) { System.err.println("Client exception: " + e.toString()); e.printStackTrace(); } } }

Other Steps and Solutions

If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus