This is a discussion on How to invoke a method on a remote object? within the Java Programming forums, part of the Software Development category; How to invoke a method on a remote object?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi MobileGeek, You may first check for the availability of the remote object and then in case remote object exist, its method is invoked. try { // Look up a remote object RObject robj = (RObject) Naming.lookup("//localhost/RObjectServer"); // Invoke method on remote object robj.aMethod(); } catch (MalformedURLException e) { } catch (UnknownHostException e) { } catch (NotBoundException e) { } catch (RemoteException e) { } Hope usefull |
| |||
| For a caller (client, peer, or applet) to be able to invoke a method on a remote object, that caller must first obtain a reference to the remote object. Most of the time, the reference will be obtained as a parameter to, or a return value from, another remote method call. For bootstrapping, the RMI system also provides a URL-based registry that allows you to bind a URL of the form //host/objectname to the remote object, where objectname is a simple string name. Once a remote object is registered on the server, callers can look up the object by name, obtain a remote object reference, and then remotely invoke methods on the object. For example, the following code binds the URL of the remote object named HelloServer to a reference for the remote object: Naming.rebind("//myhost/HelloServer", obj); Note the following about the arguments to the call: • The host defaults to the current host if omitted from the URL, and no protocol needs to be specified in the URL. • The RMI runtime substitutes a reference to the remote object’s stub for the actual remote object reference specified by the obj argument. Remote implementation objects like instances of HelloImpl never leave the virtual machine where they are created, so when a client performs a lookup in a server’s remote object registry, a reference to the stub is returned. • Optionally, a port number can be supplied in the URL: for example //myhost:1234/HelloServer. The port defaults to 1099. It is necessary to specify the port number only if a server creates a registry on a port other than the default 1099. Note – For security reasons, an application can bind or unbind only in the registry running on the same host. This prevents a client from removing or overwriting any of the entries in a server’s remote registry. A lookup, however, can be done from any host. |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How do you log in to a remote Unix box? | sundarraja | Operating Systems | 1 | 01-22-2008 03:51 AM |
| Object reference not set to an instance of an object for crystal reports in .net | KiruthikaSambandam | Database Support | 1 | 08-03-2007 03:26 AM |
| Remote control of Windows PCs simpler through PsExec than Remote Desktop | oxygen | Server Management | 1 | 07-26-2007 03:27 AM |
| How can I invoke another program from C? | Sabari | C and C++ Programming | 1 | 07-17-2007 04:05 AM |
| How can I invoke another program or command and trap its output in C? | Sabari | C and C++ Programming | 1 | 07-17-2007 04:01 AM |