?? main.java
字號:
/*
* Copyright 1999 by dreamBean Software,
* All rights reserved.
*/
package smartworld.client;
import java.io.IOException;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Properties;
import smartworld.interfaces.SmartWorld;
/**
* This test application client locates a server object, and invokes it.
*
* This demonstrates a barebones client which is about as simple as it gets, RMI-wise at least.
*
* @author Rickard 謆erg (rickard@dreambean.com)
* @version $Revision:$
*/
public class Main
implements Runnable
{
// Static --------------------------------------------------------
/**
* Start the client as a stand-alone application.
*
* @param args
* @exception Exception
*/
public static void main(String[] args)
throws Exception
{
System.setSecurityManager(new SecurityManager()
{
public void checkPermission(java.security.Permission p)
{
}
});
new Main().run();
}
// Public --------------------------------------------------------
// Runnable implementation ---------------------------------------
/**
* Run the client. Lookup the server from a RMI-registry, call it, and print the result.
*
*/
public void run()
{
try
{
// Locate remote object
SmartWorld server = (SmartWorld)Naming.lookup(SmartWorld.NAME);
/*
// Call it
String result = server.helloWorld("World");
// Print result
System.out.println(result);
// Say hi
server.sayHi("World", true);
// Test arrays
server.testArrays(new int[1][2]);
*/
// Test reconnect
while (true)
{
try
{
System.out.println(server.helloWorld("World"));
} catch (RemoteException e)
{
System.out.println("Server not available:"+e.getMessage());
}
Thread.sleep(1000);
}
} catch (NotBoundException e)
{
System.out.println("The server could not be found");
e.printStackTrace(System.err);
} catch (MalformedURLException e)
{
System.out.println("The server name was incorrect");
e.printStackTrace(System.err);
} catch (Exception e)
{
System.out.println("The object could not be created");
e.printStackTrace(System.err);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -