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

📄 server.java

📁 《JAVA分布式程序设计》一书的源代码。
💻 JAVA
字号:
/** * @(#)Server.java * @author Qusay H. Mahmoud */import java.io.*;import java.net.*;import java.util.*;import java.lang.*;public class Server extends Thread {    // The port number on which the server will be listening on    public static final int MATH_PORT = 3333;    protected ServerSocket listen;    // constructor.    public Server() {     try {        listen = new ServerSocket(MATH_PORT);     } catch(IOException ex) {        System.out.println("Exception..."+ex);     }     this.start();    }    // multi-threading -- create a new connection for each request    public void run() {    try {       while(true) {       Socket client = listen.accept();       Connects cc = new Connects(client);     }     } catch(IOException e) {       System.out.println("Exception..."+e);     }    }    // main program    public static void main(String argv[]) throws IOException {     new Server();    }}class Connects extends Thread {    Socket client;    BufferedReader is;    DataOutputStream os;    ArrayIO aio = new ArrayIO();    ArrayMath am = new ArrayMath();    public Connects(Socket s) { // constructor        client = s;        try {           is = new BufferedReader(new InputStreamReader(client.getInputStream()));           os = new DataOutputStream(client.getOutputStream());        } catch (IOException e) {           try {             client.close();           } catch (IOException ex) {             System.out.println("Error while getting socket streams.."+ex);           }           return;        }        this.start(); // Thread starts here...this start() will call run()    }     public void run() {	int a1[] = new int[10];   	int a2[] = new int[10];    try {	a1 = aio.readArray(is);	a2 = aio.readArray(is);     } catch(Exception ioe) {     }     int r[] = new int[10];     r = am.addArray(a1, a2);     try {        aio.writeArray(os, r);     } catch(Exception e) {	e.printStackTrace();     }  }}

⌨️ 快捷键说明

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