1 / 28

Java 網路程式設計

Java 網路程式設計. 第 10 章 認識 Web 架構下的 Java 類別. 三種知名的分散式檔案系統. NFS(Network File System), Sun Microsystems, Inc 。 AFS(Andrew File System), Transarc Corporation 。 DFS(Distributed File System), OSF DCE 的一部分。. 分散式檔案系統. NFS 應用的例子. AFS 應用的例子. DCE 的結構. 思索網路應用的開發. 主從式架構 分散式系統 (Distributed System).

deva
Download Presentation

Java 網路程式設計

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java網路程式設計 第10章 認識Web架構下的Java類別

  2. 三種知名的分散式檔案系統 • NFS(Network File System), Sun Microsystems, Inc。 • AFS(Andrew File System), Transarc Corporation。 • DFS(Distributed File System), OSF DCE的一部分。

  3. 分散式檔案系統

  4. NFS應用的例子

  5. AFS應用的例子

  6. DCE的結構

  7. 思索網路應用的開發 • 主從式架構 • 分散式系統(Distributed System)

  8. 網路上可能有的主從架構關係

  9. 主從架構的分類 • 從主端(或伺服端)的特性來分類 • 從主從之間的關係來分類

  10. 各種主從架構 • 同時性連線導向(Concurrent, Connection-Oriented) • 同時性非連線導向(Concurrent, Connectionless) • 複迴性連線導向(Iterative, Connection-Oriented) • 複迴性非連線導向(Iterative, Connectionless)

  11. MUSIC模型在傳統的電腦環境中的角色

  12. 各種分散式的電腦系統

  13. 與分散式系統容易混淆在一起的名詞

  14. 進行設計與開發的工作流程

  15. 分散式系統的功能性結構(實例)

  16. 分散式系統實際部署的情況

  17. 主從架構型分散式系統的開發技巧

  18. 主從架構的變遷

  19. 主從架構型系統的開發流程

  20. 主從架構系統開發的基本觀念 • 需求分析 • 環境的規劃與建立 • 應用系統的設計 • 資料庫設計 • 應用系統的分割 • 效能調整與系統測試

  21. 二重式分割

  22. 三重式的主從架構

  23. 三重式的Intranet架構

  24. 四重式或更多重式的Intranet架構

  25. 從Web架構下的Java類別出發 • HTTP協定 • HTTPRequest • URL網址

  26. 測試自己建立的HTTP server

  27. MyHTTPServer.java import java.net.*; class MyHTTPServer { public static void main(String[] args) { ServerSocket server; Socket client; HTTPRequest request; try { server = new ServerSocket(1250); while (true) { client = server.accept(); request = new HTTPRequest(client); request.process(); } } catch (Exception e) { System.err.println("無法啟動HTTP Server : " + e.getMessage()); e.printStackTrace(); } } }

  28. HTTPRequest.java import java.net.*; import java.io.*; import java.util.*; class HTTPRequest { private Socket client; public HTTPRequest(Socket client) { this.client = client; } public void process() { // 取得client端的輸入與輸出串流 try { PrintStream outputStream = new PrintStream(client.getOutputStream()); BufferedReader bufr =new BufferedReader(new InputStreamReader(client.getInputStream())); // 讀取HTTP請求 String request = bufr.readLine().trim(); // 處理請求的內容 StringTokenizer stringToken = new StringTokenizer(request); // 讀取method String header_method = stringToken.nextToken(); // 檢查是否支援method if (!header_method.equals("GET")) { outputStream.print("HTTP協定不支援的method\r\n"); outputStream.flush(); return; } // 讀取URI String header_uri = stringToken.nextToken(); // 讀取header StringBuffer returnDocument = new StringBuffer(); // 建立回應 returnDocument.append("注意URL中所指定的檔案為 : " + header_uri + "\r\n"); returnDocument.append("檔案儲存的位置是相對於document root \n"+ " 跟一般的HTTP server的規矩一樣,client端需提供以下的header資訊 :\r\n"); String line = null; // 讀取header的其餘部分, 直到遇到空白行 while ((line = bufr.readLine().trim()) != null && line.length() > 0) { returnDocument.append(line + "\r\n"); } returnDocument.append("在這樣的運作下才能打開檔案傳資訊給client\r\n"); // 傳回response outputStream.print("HTTP/1.0 200 OK\r\n"); outputStream.print("Content-length: " + returnDocument.length() + "\r\n"); outputStream.print("Content-type: text/plain\r\n\r\n"); outputStream.print(returnDocument); outputStream.flush(); } catch (Exception e) { System.err.println("無法處理HTTPRequest: "+ e.getMessage()); e.printStackTrace(); } finally { try { client.close(); } catch (IOException e) { // 忽略不處理 } } } }

More Related