Java Access 5-1 Server Client Client Server Server Client 5-2 DataInputStream Class java.io.datainptstream (extends) FilterInputStream InputStream Obj

Similar documents
JavaIO.PDF


<4D F736F F D20BAF4BADEA457BDD2B1D0A7F75F4A415641B57BA6A1B2D52E646F63>

Java java.lang.math Java Java.util.Random : ArithmeticException int zero = 0; try { int i= 72 / zero ; }catch (ArithmeticException e ) { // } 0,

OOP with Java 通知 Project 6: 6 月 6 日晚 9 点

Chapter 9: Objects and Classes

OOP with Java 通知 Project 6: 5 月 30 日晚 9 点

untitled

Microsoft Word - newJavaA4.doc

3.1 num = 3 ch = 'C' 2

内 容 简 介 本 书 是 一 本 关 于 语 言 程 序 设 计 的 教 材, 涵 盖 了 语 言 的 基 本 语 法 和 编 程 技 术, 其 中 包 含 了 作 者 对 语 言 多 年 开 发 经 验 的 总 结, 目 的 是 让 初 学 的 读 者 感 受 到 语 言 的 魅 力, 并 掌

untitled

Microsoft Word - 01.DOC

java2d-4.PDF

OOP with Java 通知 Project 6: 5 月 24 日晚 9 点

1.JasperReport ireport JasperReport ireport JDK JDK JDK JDK ant ant...6

(TestFailure) JUnit Framework AssertionFailedError JUnit Composite TestSuite Test TestSuite run() run() JUnit

2 Java 语 言 程 序 设 计 教 程 简 单 性 Java 语 言 的 语 法 与 C 语 言 和 C++ 语 言 很 接 近, 使 得 大 多 数 程 序 员 很 容 易 学 习 和 使 用 Java 另 一 方 面,Java 丢 弃 了 C++ 中 很 少 使 用 的 很 难

1: public class MyOutputStream implements AutoCloseable { 3: public void close() throws IOException { 4: throw new IOException(); 5: } 6:

EJB-Programming-4-cn.doc

chp6.ppt

使 用 Java 语 言 模 拟 保 险 箱 容 量 门 板 厚 度 箱 体 厚 度 属 性 锁 具 类 型 开 保 险 箱 关 保 险 箱 动 作 存 取 款

untitled

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

2009年9月全国计算机等级考试二级Java真题及答案

雲端 Cloud Computing 技術指南 運算 應用 平台與架構 10/04/15 11:55:46 INFO 10/04/15 11:55:53 INFO 10/04/15 11:55:56 INFO 10/04/15 11:56:05 INFO 10/04/15 11:56:07 INFO

30.00% 25.00% 25.00% 22.50% 20.00% 15.00% 12.50% 15.00% 12.50% 10.00% 7.50% 5.00% 2.50% 2.50% 0.00% 文 学 理 学 工 学 法 学 教 育 学 管 理 学 历 史 学 艺 术 学 ( 三 ) 学 生

javaexample-02.pdf

詞 彙 表 編 號 詞 彙 描 述 1 預 約 人 資 料 中 文 姓 名 英 文 姓 名 身 份 證 字 號 預 約 人 電 話 性 別 2 付 款 資 料 信 用 卡 別 信 用 卡 號 信 用 卡 有 效 日 期 3 住 房 條 件 入 住 日 期 退 房 日 期 人 數 房 間 數 量 入

2009年3月全国计算机等级考试二级Java语言程序设计笔试试题

Java

Chapter 9: Objects and Classes

OOP with Java 通知 Project 4: 4 月 18 日晚 9 点 关于抄袭 没有分数

OOP with Java 通知 Project 4: 4 月 19 日晚 9 点

计 算 机 系 统 应 用 年 第 25 卷 第 4 期 线 程 的 复 用 [2,3]. 通 常 情 况 下, 服 务 器 端 程 序 在 启 动 时 创 建 若 干 数 量 的 线 程 对 象 并 缓 存 起 来, 此 时 它 们 处 于

中 文 摘 要 智 慧 型 手 機 由 於 有 強 大 的 功 能, 以 及 優 渥 的 便 利 性, 還 能 與 網 路 保 持 隨 時 的 鏈 結 與 同 步 更 新, 因 此 深 受 廣 大 消 費 者 喜 愛, 當 然, 手 機 遊 戲 也 成 為 現 代 人 不 可 或 缺 的 娛 樂 之

Microsoft Word - Broker.doc

Microsoft PowerPoint - course2.ppt

OOP with Java 通知 Project 4: 5 月 2 日晚 9 点

Swing-02.pdf

CC213

目 录 实 验 一 : 熟 悉 Java 开 发 环 境... 1 实 验 二 : 类 与 面 向 对 象... 7 实 验 三 : 继 承 和 多 态 实 验 四 : 异 常 处 理 实 验 五 : 流 文 件 及 基 于 文 本 的 应 用... 23

MRSTERY E / / / Wat er 4 Wat er Wat er m 2~ ~

電機工程系認可證照清單 /7/1

EJB-Programming-3.PDF

BPS6.0 Web服务集成和短流程功能使用手册

9, : Java 19., [4 ]. 3 Apla2Java Apla PAR,Apla2Java Apla Java.,Apla,,, 1. 1 Apla Apla A[J ] Get elem (set A) A J A B Intersection(set A,set B) A B A B

View:Struts 提 供 了 action form 创 建 form bean, 用 于 在 controller 和 view 间 传 输 数 据 此 外,Struts 提 供 了 自 定 义 JSP 标 签 库, 辅 助 开 发 者 用 JSP 创 建 交 互 式 的 以 表 单 为 基

Microsoft Word - ch04三校.doc

FileMaker 15 ODBC 和 JDBC 指南

Microsoft Word - JAVA3.rtf

FileMaker 16 ODBC 和 JDBC 指南

使用MapReduce读取XML文件

OOP with Java 通知 Project 3 提交时间 3 月 29 日晚 9 点 Piazza Project 2 投票

untitled

untitled

Guava学习之Resources

Java 1 Java String Date

RUN_PC連載_12_.doc

SDK 概要 使用 Maven 的用户可以从 Maven 库中搜索 "odps-sdk" 获取不同版本的 Java SDK: 包名 odps-sdk-core odps-sdk-commons odps-sdk-udf odps-sdk-mapred odps-sdk-graph 描述 ODPS 基

《大话设计模式》第一章

Microsoft PowerPoint - ch02

礼仪玉和葬玉

概述

Learning Java

untitled

1.5招募说明书(草案)

Cover-3.indd, page Normalize


人 間 菩 提 Part 1 人 間 菩 提 Part 2 清 涼 菩 提 正 覺 修 行 清 心 發 願 自 重 ----

FP.pdf

OOP with Java 通知 Project 3: 3 月 29 日晚 9 点 4 月 1 日上课

强迫症毁灭天才

<4D F736F F D20D0C5CFA2BBAFB7A2D5B9D6D8B5E3D7A8CFEEB9E6BBAE2E646F63>

关于建立境内违法互联网站黑名单管理制度的通知

? 這 全 都 是 市 政 府 提 供 給 我 的 資 料 低 底 盤 公 車 計 畫 96 年 預 算 新 台 幣 4,500 萬 元 97 年 預 算 新 台 幣 1 億 6,500 萬 元 98 年 預 算 新 台 幣 3 億 2,300 萬 元, 共 有 307 台 低 底 盤 公 車,99

Microsoft PowerPoint - CH06.ppt [相容模式]

ZW1.PDF

FY.DOC

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

51 C 51 isp 10 C PCB C C C C KEIL

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

JBuilder Weblogic

(HMI) IO A

<4D F736F F F696E74202D20332D322E432B2BC3E6CFF2B6D4CFF3B3CCD0F2C9E8BCC6A1AAD6D8D4D8A1A2BCCCB3D0A1A2B6E0CCACBACDBEDBBACF2E707074>

Microsoft Word - 投影片ch14


新版 明解C++入門編

(6) 要 求 付 款 管 理 员 从 预 订 表 中 查 询 距 预 订 的 会 议 时 间 两 周 内 的 预 定, 根 据 客 户 记 录 给 满 足 条 件 的 客 户 发 送 支 付 余 款 要 求 (7) 支 付 余 款 管 理 员 收 到 客 户 余 款 支 付 的 通 知 后, 检

while ((ch = fr.read())!= -1) { System.out.print((char) ch); fr.close(); 例 3: 用 BufferedReader 读 TXT 文件 public class FileReaderDemo3 { public static v

Servlet

untitled

4.1 AMI MQSeries API AMI MQI AMI / / AMI JavaC C++ AMI / AMI AMI - / /

软件工程文档编制

提问袁小兵:

Java第一天 年4月23日

Java ¿ª·¢ 2.0: Óà Hadoop MapReduce ½øÐдóÊý¾Ý·ÖÎö

建模与图形思考

北 风 网 讲 师 原 创 作 品 ---- 仅 供 学 员 内 部 交 流 使 用 前 言 吾 尝 终 日 而 思 矣, 不 如 须 臾 之 所 学 也 ; 吾 尝 跂 而 望 矣, 不 如 登 高 之 博 见 也 登 高 而 招, 臂 非 加 长 也, 而 见

Microsoft Word - 封面

Transcription:

Message Transition 5-1 5-2 DataInputStream Class 5-3 DataOutputStream Class 5-4 PrintStream Class 5-5 (Message Transition) (Exercises)

Java Access 5-1 Server Client Client Server Server Client 5-2 DataInputStream Class java.io.datainptstream (extends) FilterInputStream InputStream Object (implements) DataInput 1 ( 07) public DataInputStream(InputStream in); in DataInputStream in 4-4 Socket.getInputStream() 2 ( ) public final boolean readboolean() throws IOException; public final char readchar() throws IOException; public final byte readbyte() throws IOException; public final short readshort() throws IOException; public final int readint() throws IOException; public final long readlong() throws IOException; public final float readfloat() throws IOException; public final double readdouble() throws IOException; [ 5-2 ]

(Message Transition) 05 public final String readline() throws IOException; ( 07) public final String readutf() throws IOException; ( 08) UTF UTF ASCII 5-3 DataOutputStream Class java.io.dataoutptstream (extends) FilterOutputStream OutputStream Object (implements) DataOutput 1 public DataOutputStream(OutputStream out); out DataOutputStream out 23-4 Socket.getOutputStream() 2 public final boolean writeboolean() throws IOException; public final char writechar() throws IOException; public final byte writebyte() throws IOException; public final short writeshort() throws IOException; public final int writeint() throws IOException; public final long writelong() throws IOException; public final float writefloat() throws IOException; public final double writedouble() throws IOException; PART 1 PART 3 PART 4 PART 2 PART 5 PART 6 [ 5-3 ]

Java Access public final String writeutf() throws IOException; ( 08) UTF UTF ASCII 5-4 PrintStream Class java.io.printstream (extends) FilterOutputStream OutputStream Object DataOutputStream 1 public PrintStream(OutputStream out); public PrintStream(OutputStream out, boolean autoflush); out DataOutputStream out 4-4 Socket.getOutputStream() autoflush true 2 ( 07) public void print(); public void print(boolean b); public void print(char c); public void print(char s[]); public void print(double d); public void print(float f); public void print(int i); public void print(long l); public void print(object o); public void print(string s); [ 5-4 ]

(Message Transition) 05 public void println(); ( 07) public void println(boolean b); public void println(char c); public void println(char s[]); public void println(double d); public void println(float f); public void println(int i); public void println(long l); public void println(object o); public void println(string s); 5-5 (Message Transition) DataInputStream PrintStream / Server/Client 07 Client Server Server Client 007 Server07.java 01 import java.net.*; 02 import java.io.*; Server07.java Client07.java Server/Client Client Server Server Client 03 public class Server07{ 04 ServerSocket SS; 05 Socket socket; 06 DataInputStream in_from_client; PART 1 PART 3 PART 4 PART 2 PART 5 PART 6 [ 5-5 ]

Java Access 07 PrintStream out_to_client; 08 static int port; 09 public Server07(){ 10 try{ 11 SS = new ServerSocket(port); 12 System.out.println("Server is created and waiting Client to connect..."); 13 socket = SS.accept(); 14 System.out.println("Client IP =" + socket.getinetaddress().gethostaddress()); 15 in_from_client = new DataInputStream(socket.getInputStream()); 16 out_to_client = new PrintStream(socket.getOutputStream()); 17 String messagein = in_from_client.readline(); 18 System.out.print(messageIn); 19 out_to_client.println("from Server: English Message and "); 20 } 21 catch(java.lang.exception e){ 22 System.out.println(e.getMessage()); 23 } 24 } 25 public static void main(string args[]){ 26 if(args.length<1) { 27 System.out.println("Usage: java Server [port]"); 28 System.exit(1); 29 } 30 port = Integer.parseInt(args[0]); 31 Server07 ServerStart=new Server07(); 32 } 33 } 06~07 / 15~16 / ( 5-2 5-4 ) 17 ( 5-2 ) 18 19 Client ( 5-4 ) 06 [ 5-6 ]

(Message Transition) 05 Client07.java 34 import java.net.*; 35 import java.io.*; 36 public class Client07{ 37 Socket socket; 38 DataInputStream in_from_server; 39 PrintStream out_to_server; 40 static int port; 41 static String iaddr; 42 static String messageout; 43 public Client07(){ 44 try{ 45 socket = new Socket(InetAddress.getByName(iaddr), port); 46 in_from_server = new DataInputStream(socket.getInputStream()); 47 out_to_server = new PrintStream(socket.getOutputStream()); 48 out_to_server.println(messageout); 49 String info = in_from_server.readline(); 50 System.out.println(info); 51 } 52 catch(ioexception e){ 53 System.out.println(e.getMessage()); } 54 } 55 public static void main(string args[]){ 56 if(args.length < 3) { 57 System.out.println("USAGE: java Client [iaddr] [port] [messageout]"); 58 System.exit(1); 59 } 60 iaddr = args[0]; 61 port = Integer.parseInt(args[1]); 62 messageout = args[2]; 63 Client07 ClientStart = new Client07(); 64 } 65 } PART 1 PART 3 PART 4 PART 2 PART 5 PART 6 [ 5-7 ]

Java Access 38~39 / 46~47 / 48 62 49 Server 06 1 javac *.java 2 Server Client Dos Server Client ( ) (1) Server java Server07 1234 Client [ 5-8 ]

(Message Transition) 05 (2) Client ( IP Port ) java Client07 163.15.40.243 1234 "From Client: English Message and " Server ( 163.15.40.243 Server IP 1234 Server Port Server Server (3) Server Client Client socket Server/Client ( Client IP Client ) 3 5-4 PrintStream println() PART 1 PART 3 PART 4 PART 2 PART 5 PART 6 [ 5-9 ]

Java Access DataOutputStream writeutf() readutf() 008 07 Server08.java Client08.java Server08.java Server/Client Client Server Server Client 01 import java.net.*; 02 import java.io.*; 03 public class Server08{ 04 ServerSocket SS; 05 Socket socket; 06 DataInputStream in_from_client; 07 DataOutputStream out_to_client; 08 static int port; 09 public Server08(){ 10 try{ 11 SS = new ServerSocket(port); 12 System.out.println("Server is created and waiting Client to connect..."); 13 socket = SS.accept(); 14 System.out.println("Client IP =" + socket.getinetaddress().gethostaddress()); 15 in_from_client = new DataInputStream(socket.getInputStream()); 16 out_to_client = new DataOutputStream(socket.getOutputStream()); 17 String messagein = in_from_client.readutf(); 18 System.out.print(messageIn); 19 out_to_client.writeutf("from Server: English Message and "); 20 } 21 catch(java.lang.exception e){ [ 5-10 ]

(Message Transition) 05 22 System.out.println(e.getMessage()); 23 } 24 } 25 public static void main(string args[]){ 26 if(args.length<1) { 27 System.out.println("Usage: java Server [port]"); 28 System.exit(1); 29 } 30 port = Integer.parseInt(args[0]); 31 Server08 ServerStart=new Server08(); 32 } 33 } 07 16 ( 5-3 ) 17 ( 5-3 ) 19 Client ( 5-3 ) 07 Client08.java 34 import java.net.*; 35 import java.io.*; 36 public class Client08{ 37 Socket socket; 38 DataInputStream in_from_server; 39 DataOutputStream out_to_server; 40 static int port; 41 static String iaddr; 42 static String messageout; 43 public Client08(){ 44 try{ 45 socket = new Socket(InetAddress.getByName(iaddr), port); 46 in_from_server = new DataInputStream(socket.getInputStream()); 47 out_to_server = new DataOutputStream(socket.getOutputStream()); PART 1 PART 3 PART 4 PART 2 PART 5 PART 6 [ 5-11 ]

Java Access 48 out_to_server.writeutf(messageout); 49 String info = in_from_server.readutf(); 50 System.out.println(info); 51 } 52 catch(ioexception e){ 53 System.out.println(e.getMessage()); } 54 } 55 public static void main(string args[]){ 56 if(args.length < 3) { 57 System.out.println("USAGE: java Client [iaddr] [port] [messageout]"); 58 System.exit(1); 59 } 60 iaddr = args[0]; 61 port = Integer.parseInt(args[1]); 62 messageout = args[2]; 63 Client08 ClientStart = new Client08(); 64 } 65 } 39 47 48 62 49 Server 07 1 javac *.java [ 5-12 ]

(Message Transition) 05 2 Server Client Dos Server Client ( ) (1) Server java Server08 1234 Client (2) Client ( IP Port ) java Client08 163.15.40.243 1234 "From Client: English Message and " Server ( 163.15.40.243 Server IP 1234 Server Port Server Server ) (3) Server Client Client socket Server/Client ( Client IP Client ) PART 1 PART 3 PART 4 PART 2 PART 5 PART 6 [ 5-13 ]

Java Access 3 5-3 DataOutputStream println() readutf() [ 5-14 ]

(Message Transition) 05 Exercises 1. DataInputStream Class 2. DataOutputStream Class 3. PrintStream Class 4. DataInputStream 5. PrintStream 6. readline() 7. println() PART 1 PART 3 PART 4 PART 2 PART 5 PART 6 [ 5-15 ]