⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sortclient.java

📁 this gives details of the network programming
💻 JAVA
字号:
// Sample client for RemotSort RMI object
// 
// This client expects a hostname on the command line.
// The hostname is the host running the RMI server with a sort object.
// 
// The client reads lines from stdin (until EOF), putting them in a vector which is then
// sent to the remote sort procedure. The remote sort procedure returns a new List object
// (which is the result of the sort). Then the client prints out the sorted list.

import java.rmi.*;
import java.util.*;
import java.io.*;

public class SortClient {
    
    public static void main(String args[]) {
	if (args.length != 1) {
	    System.out.println("Usage: SortClient hostname");
	} else {
	    System.out.println("Remote Sort Client Starting");

	    // Grab the command line parameters
	    String hostname = args[0];

	    try {
		// The naming service returns a generic object
		// the name of the server is specified using an rmi URL
		// Check out the java documentation on the Naming class
		// (in java.rmi) for more info on rmi URLs

		Object o = Naming.lookup("rmi://"+hostname+"/sort");

		// need to cast the generic object as something that
		// supports the RemoteMath interface.

		RemoteSort r = (RemoteSort) o;

		// Now we have a RemoteSort object. Let's get something to sort.
		// read all lines from stdin and put in a vector.
		
		Vector v = new Vector();
		String line;
		// read in strings from stdin and put in vector

		BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
		try { 
		    while ( (line = in.readLine())!=null) {
			v.add(line);
		    }
		} catch (IOException e) {
		    e.printStackTrace();
		}

		// v is now a vector of Strings - call the remote sort method
		// DLH need to create a List object - I would think I could 
		// pass a vector (since it implements List), but it doesn't seem
		// to work...

		List l = (List) v;
		l = r.sort(l);

		// and print out the result
		for (Iterator i = l.iterator(); i.hasNext();) {
		    System.out.println(i.next());
		}

	    } catch (Exception e) {
		System.out.println("ERROR " + e.getMessage());
		e.printStackTrace();
	    }
	}
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -