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

📄 client.java

📁 《JAVA分布式程序设计》一书的源代码。
💻 JAVA
字号:
/** * @(#)Client.java * @author Qusay H. Mahmoud */import java.io.*;import java.net.*;public class Client {        public final static int REMOTE_PORT = 3333;    static int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};    static int b[] = {11, 12, 13, 14, 15, 16, 17, 18, 19, 20};    public static void main(String argv[]) throws Exception {	Socket cl = null, cl2=null;	BufferedReader is = null;	DataOutputStream os = null;        ArrayIO aio = new ArrayIO();	try {	   cl = new Socket("hostname",REMOTE_PORT);	   is = new BufferedReader(new InputStreamReader(cl.getInputStream()));	   os = new DataOutputStream(cl.getOutputStream());	} catch(UnknownHostException e1) {	   System.out.println("Unknown Host: "+e1);	} catch (IOException e2) {	   System.out.println("Erorr io: "+e2);	}	try {	    	   aio.writeArray(os, a);           aio.writeArray(os, b);	} catch (IOException ex) {	   System.out.println("error writing to server..."+ex);	}		// receive results 	int result[] = new int[10];	try {           result = aio.readArray(is);	} catch(Exception e) {	   e.printStackTrace();	}	System.out.println("The sum of the two arrays is: ");	for (int j=0; j<result.length; j++) {	   System.out.print(result[j]+" ");	}        System.out.println("");	// close input stream, output stream and connection	try {           is.close();           os.close();	   cl.close();	} catch (IOException x) {	   System.out.println("Error writing...."+x);	}    }}

⌨️ 快捷键说明

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