?? hellosocket.java
字號:
/*
* Copyright 1999 by dreamBean Software,
* All rights reserved.
*/
package masteringrmi.hellosocket.client;
import java.applet.Applet;
import java.awt.Label;
import java.rmi.RemoteException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import masteringrmi.hellosocket.interfaces.HelloWorld;
/**
* This is an application that will talk to the remote object.
* After lookup of remote object, it will query it for a
* greeting, which will be shown in the system console.
*
* The reason that this example uses an application and not an applet as client,
* is that to get the name of the client we need to have a permission to read the
* system properties, something which an applet doesn't have.
*
* @see HelloWorld
* @author Rickard 謆erg (rickard@dreambean.com)
*/
public class HelloSocket
implements Runnable
{
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
public static void main(String[] args)
{
new HelloSocket().run();
}
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
// Runnable implementation ---------------------------------------
public void run()
{
try
{
// Create URL to remote server (which is localhost in this case)
String url = "rmi://localhost/"+HelloWorld.NAME;
// Locate remote object
HelloWorld server = (HelloWorld)new InitialContext().lookup(url);
// Call server and show response
System.out.println(server.helloWorld());
System.out.println(server.helloWorld());
System.out.println(server.helloWorld());
// Locate remote object
server = (HelloWorld)new InitialContext().lookup(url);
// Call server and show response
System.out.println(server.helloWorld());
System.out.println(server.helloWorld());
System.out.println(server.helloWorld());
} catch (NamingException e)
{
System.out.println("The server could not be found");
e.printStackTrace(System.err);
} catch (RemoteException e)
{
System.out.println("The object could not be called");
e.printStackTrace(System.err);
} catch (Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace(System.err);
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -