- compile server ด้วย command line:
javac Server.java
- compile client ด้วย command line:
javac Client.java
หมายเหตุ: Compile Server กับ Client บน Terminal ที่แยกกัน
- บน Terminal ของ Server
Run server ด้วย command line:
java Server <port>
- บน Terminal ของ Client
Run client ด้วย command line:
javac Client <server_ip> <port> <filename>
- Server จะมี file ให้ทดสอบได้แก่ file1.txt, file2.txt, file3.txt ให้ทำการ run เพื่อให้ client request file ด้วย filename ดังกล่าว
- เมื่อ client ส่ง request แล้ว server จะรับ request และส่ง packet ของ file ให้\
- กรณีไม่มี packet loss.
Terminal ของ server จะแสดงผลดังนี้
Client requested: file1.txt
Send packet: 0
Got ack: 0
Send packet: 1
Got ack: 1
Send packet: 2
Got ack: 2
Send packet: 3
Got ack: 3
Send packet: 4
Got ack: 4
Send packet: 5
Got ack: 5
Send packet: 6
Got ack: 6
Send packet: 7
Got ack: 7
Send packet: 8
Got ack: 8
Send packet: 9
Got ack: 9
Send packet: 10
Got ack: 10
Complete sending file
Terminal ของ client จะแสดงผลดังนี้
send ack: 0
send ack: 1
send ack: 2
send ack: 3
send ack: 4
send ack: 5
send ack: 6
send ack: 7
send ack: 8
send ack: 9
send ack: 10
Complete receiving file
- ใน folder ชื่อ client-folder จากเดิมที่เป็น folder เปล่า เมื่อได้รับ packet แล้วจะปรากฏ file ที่มีข้อมูลที่ถูกส่งมาจาก server
สามารถจำลองโดยการระบุ loss rate ได้
- บน Terminal ของ Server
Run server ด้วย command line:
java Server <port> <loss_rate>
เข่น
java Server 1234 0.2
- หมายถึงให้จำลอง packet loss โดยสุ่ม drop packet ที่ drop rate เท่ากับ 0.2 (หากส่ง 10 packets จะถูก drop 2 packets)
- บน Terminal ของ Client ทำการ run ด้วย command line แบบเดิม
Terminal ของ server จะแสดงผลดังนี้ (ขึ้นอยู่กับ sequence number ของ packet ที่ loss)
Client requested: file1.txt
Send packet: 0
Got ack: 0
Send packet: 1
Got ack: 1
Send packet: 2
Got ack: 2
Simulated loss of packet seq 3
Timeout, resending seq 3
Simulated loss of packet seq 3
Timeout, resending seq 3
Send packet: 3
Got ack: 3
Send packet: 4
Got ack: 4
Simulated loss of packet seq 5
Timeout, resending seq 5
Send packet: 5
Got ack: 5
Send packet: 6
Got ack: 6
Send packet: 7
Got ack: 7
Send packet: 8
Got ack: 8
Send packet: 9
Got ack: 9
Send packet: 10
Got ack: 10
Complete sending file
Terminal ของ client จะแสดงผลดังนี้
send ack: 0
send ack: 1
send ack: 2
send ack: 3
send ack: 4
send ack: 5
send ack: 6
send ack: 7
send ack: 8
send ack: 9
send ack: 10
Complete receiving file
- ใน folder ชื่อ client-folder จะปรากฏ file ที่มีข้อมูลที่ถูกส่งมาจาก server