首页 > 其他分享 >COMP3331 9331 HTTP & Socket Programming

COMP3331 9331 HTTP & Socket Programming

时间:2024-09-25 18:33:55浏览次数:1  
标签:COMP3331 HTTP trace Programming server file response your

COMP3331 9331 Computer Networks and Applications

Lab Exercise 2: HTTP & Socket Programming

  • Specification
  • Make Submission
  • Check Submission
  • Collect Submission

Objectives:

  • Gain insights into the operation of HTTP.
  • Get familiar with basic socket programming.
  • Preparation for programming assignment.

Prerequisites:

  • Week 2 Lectures
  • Relevant Parts of Chapter 2 of the textbook (Sections 2.2 on HTTP and 2.7 on Socket Programming)
  • Basic understanding of Linux. A good resource is here , but there are several other resources online.
  • Several socket programming resources and sample codes for all three programming languages are available on this page .
  • PingServer.java
  • http-wireshark-trace-1
  • http-wireshark-trace-2

Marks: 10 marks

  • This lab comprises several exercises. Please note that not all the exercises for this lab are marked. You have to submit a report containing answers to selected exercises only.
  • Please attend the lab in your allocated lab time slot.
  • We expect the students to go through as many lab exercises as possible at home and come to the lab to clarify any doubts about the procedure/specifications.

Deadline:

10:00 am Tuesday 01 /10/2024 . You can submit as many times as you wish before the deadline. A later submission will override the earlier submission, so make sure you submit the correct file. Do not leave until the last moment to submit, as there may be technical or communications errors, and you will not have time to rectify them.

ELP (Equitable Learning Plan) Arrangements : If you have submitted ELP documentation and wish to avail of your conditions, you must contact [email protected] .

Late Report Submission Penalty:

A late penalty will be applied as follows:

  • up to 24 hours after the deadline: 5% reduction
  • more than 24 hours and less than 48 hours after the deadline: 10% reduction
  • more than 48 hours after the deadline: NOT accepted

Note that the above penalty is applied to your final mark in the report. For example, if you submit your lab report 2 days late and your score on the lab is 8, then your final mark will be 8 - 0.8 (10% penalty) = 7.2.

No submissions will be accepted after 10 :00 am Thursday, 03/10/2024.

Submission Instructions:

Prepare a PDF document, Lab2.pdf, with answers to all questions for all exercises and PingClient.py or PingClient.java or PingClient.c (Depending on your pogramming language of choice) . Submit the report/code files using the give or WebCMS interface. You can submit it from a lab machine or SSH into the CSE login server. Instructions to ssh into CSE login servers are here .

  1. Save your report as Lab2.pdf and codes
  2. Next, type: give cs3331 Lab2 Lab2.pdf PingClient.py (For python code)

If you want to include other supporting documents along with the report, create a tar archive of all the files called Lab2.tar.

  1. Put all your files (e.g., Lab2.pdf, PingClient.py, output.txt) in a directory lab2.
  2. Type “tar -cvf Lab2.tar lab2”
  3. Next, type: give cs3331 Lab2 Lab2.tar (Or use WebCMS interface)
  • Please make sure that the tar archive is not corrupted. You can untar (use tar -xvf Lab2.tar) the created archive to check that all the files are intact.
  • The maximum file size for submission is25 MB .
  • COMP9331 students should also use 'give cs3331'

Original Work Only:

You are strongly encouraged to discuss the questions with other students in your lab. However, each student must submit his or her own work. You may need to refer to the material indicated above (particularly socket programming links) and conduct your own research to answer the questions.

System Compatibility (Very Important):

We will test your code on CSE machines via the command-line interface. Note that CSE machines support gcc version 12.2, Java ( openjdk 17.0.10 ), Python 3.11. Thus, you must test your code on CSE machines before submitting it. This is particularly important if you write your code on your own machine and use an IDE. Before submitting, you MUST test your code on CSE machines (via the command line). If we cannot get your code to work on CSE machines, then we can't mark it, and unfortunately, you won't receive any marks. This point is also relevant to the assignment.

Exercise 1: Using Telnet to interact with a Web Server (Unmarked, not to be included in the report)

Follow the steps described below.

Step 1: Open an xterm window. Enlarge the size of your xterm window so that it is reasonably large and covers almost the entire screen.

Step 2: Telnet to the vision.ucla.edu web server by typing:

$telnet vision.ucla.edu 80

Note that the port number for all web servers is “80”.

Step 3: Retrieve the main webpage by typing:

GET / HTTP/1.1

host: www.vision.ucla.edu

Important Note : Press the carriage return twice after typing the last line.

Question 1: What is the content type of the response? What is the size of the response? When was the webpage last modified? Do you see an "Accept-Ranges" header field? What may this be used for?

Step 4: Now execute the HEAD method. When a server receives a request with the HEAD method, it responds with only the message header lines (i.e. the response to the GET method minus the actual requested object).

HEAD / HTTP/1.1

host: www.vision.ucla.edu

Question 2: What is the content type of the response? What is the size of the response?

Question 3: Using telnet, find a way to get the people.html webpage from vision.ucla.edu

Question 4: Why must the host be included in the GET (and HEAD) HTTP 1.1 request messages?

Exercise 2: Understanding Internet Cookies (unmarked, not to be included in the report)

Question 1. Repeat steps 1-3 in the previous experiment for www.google.com.au . Does the site set a cookie in your browser? How can you tell by purely examining the HTTP response message received using telnet? How about www.vision.ucla.edu? Do you think this site will set a cookie in your browser?

Question 2. Open a web browser (Firefox/IceWeasel/Mozilla preferred). Go to the browser preferences and remove all existing cookies. Access the Google home page and then view the cookies. How many cookies are stored on your machine? Which sites installed the cookies?

Exercise 3: Using Wireshark to understand basic HTTP request/response messages (2.5 marks, include in your report)

We will not be running Wireshark on a live network connection (You are strongly encouraged to try this on your native machine. Pointers are provided at the end of this exercise). The CSE network administrators do not permit live traffic monitoring for security reasons. Instead, for all our lab exercises, we will use several trace files collected by running Wireshark by one of the textbook’s authors. For this particular experiment, download the following trace file: http-wireshark-trace-1

NOTE: IT IS NOT POSSIBLE TO RUN WIRESHARK VIA SSH. IT IS A RESOURCE-INTENSIVE PROGRAM, AND IT WOULD SLOW DOWN THE CSE LOGIN SERVERS. IF YOU WANT TO WORK REMOTELY, THEN MAKE SURE YOU ARE USING VLAB. WIRESHARK IS AVAILABLE ON ALL LAB MACHINES AND IN VLAB. HOWEVER, IT CANNOT BE INVOKED FROM THE COMMAND LINE. INSTEAD, GO TO THE APPLICATION MENU AND SELECT "INTERNET" AND "WIRESHARK". YOU CAN ALSO DOWNLOAD AND INSTALL WIRESHARK ON YOUR PERSONAL MACHINE.

The following indicates the steps involved:

Step 1: Start Wireshark natively on your machine or through VLAB, as noted above.

Step 2: Load the trace file http-wireshark-trace-1 using the File pull-down menu, choosing Open and selecting the appropriate trace file. This trace file captures a simple request/response interaction between a browser and a web server.

Step 3: You will see many packets in the packet listing window. Since we are currently only interested in HTTP, we will filter out all the other packets by typing “http” in lowercase in the Filter field and pressing Enter. You should now see only HTTP packets in the packet-listing window.

Step 4: Select the first HTTP message in the packet-listing window and observe the data in the packet-header detail window. Recall that since each HTTP message is encapsulated inside a TCP segment, which is encapsulated 代 写COMP3331 9331 HTTP & Socket Programming  inside an IP datagram, which is encapsulated within an Ethernet frame, Wireshark displays the Frame, Ethernet, IP, and TCP packet information as well. We want to minimize the amount of non-HTTP data displayed (we’re interested in HTTP here and will be investigating these other protocols in later labs), so make sure the boxes at the far left of the Frame, Ethernet, IP and TCP information have a right-pointing arrowhead (which means there is hidden, undisplayed information), and the HTTP line has a down-pointing arrowhead (which means that all information about the HTTP message is displayed).

NOTE: Please neglect the HTTP GET and response for favicon.ico, (the third and fourth HTTP messages in the trace file. Most browsers automatically ask the server if the server has a small icon file that should be displayed next to the displayed URL in the browser. We will ignore references to this pesky file in this lab.)

By looking at the information in the HTTP GET and response messages (the first two messages), answer the following questions:

Question 1: What is the status code and phrase returned from the server to the client browser?

Question 2: When was the HTML file the browser retrieves last modified at the server? Does the response also contain a DATE header? How are these two fields different?

Question 3: Is the connection established between the browser and the server persistent or non-persistent? How can you infer this?

Question 4: How many bytes of content are being returned to the browser?

Question 5: What is the data contained inside the HTTP response packet?

Note: Students are strongly encouraged to use Wireshark to capture real network traffic on their own machines. Check https://www.wireshark.org/download.html for details. Once you have Wireshark installed, do the following. Clear your web browser's cache (Firefox->Tools->Clear Recent History). Launch the Wireshark tool by typing Wireshark in the command line. Start Wireshark capture by clicking on capture -> interfaces -> click Start on the interface eth0. Run the Web browser and enter a URL for a website (e.g. www.bbc.co.uk ). Stop capturing packets when the web page is fully loaded. Examine the captured trace and answer the questions above. This is just for you to try in your own time. You do not have to include this in your report.

Exercise 4: Using Wireshark to understand the HTTP CONDITIONAL GET/response interaction (2.5 marks, include in your report)

For this particular experiment, download the second trace file: http-wireshark-trace-2

The following indicates the steps for this experiment:

Step 1: Start Wireshark natively on your machine or through VLAB, as noted above.

Step 2: Load the trace file http-wireshark-trace-2 using the File pull-down menu, choosing Open and selecting the appropriate trace file. This trace file captures a request-response between a client browser and a web server where the client requests the same file from the server within a few seconds.

Step 3: Filter out all the non-HTTP packets and focus on the HTTP header information in the packet-header detail window.

We will focus on the first two GET requests and the corresponding responses (the first 4 HTTP messages).

Question 1: Inspect the contents of the first HTTP GET request from the browser to the server. Do you see an “IF-MODIFIED-SINCE” line in the HTTP GET?

Question 2: Does the HTTP response from the server indicate the last time the requested file was modified?

Question 3: Now inspect the contents of the second HTTP GET request from the browser to the server. Do you see the “IF-MODIFIED-SINCE:” and “IF-NONE-MATCH” lines in the HTTP GET? If so, what information is contained in these header lines?

Question 4: What is the HTTP status code and phrase returned from the server in response to this second HTTP GET? Did the server explicitly return the file's contents? Explain.

Question 5: What is the value of the Etag field in the 2nd response message, and how is it used? Is the Etag value the same as in the 1 st response?

Exercise 5: Ping Client (5 marks, submit source code as a separate file, include sample output in the report)

Objective:

In this exercise, you will implement a Ping client using UDP, similar to the standard Ping tool, with enhanced functionality. You will calculate Round-Trip Time (RTT) and report additional statistics such as the percentage of packets acknowledged, total transmission time, and jitter. The server, PingServer.java , is provided and simulates network conditions by introducing packet loss and delays.

Ping Server (Provided):

You are given the code for the Ping server ( PingServer.java ). The server listens for UDP packets and responds with the same data it receives. However, the server may drop packets or delay responses based on predefined parameters.

Your Task: Implementing Ping Client

You will implement a client ( PingClient.java, PingClient.c, or PingClient.py ) that performs the following tasks:

  1. Send 15 ping requests to the server.
  2. Each ping request should include:

o The keyword PING .

o A sequence number starting from a random number between 10,000 and 20,000.

o A timestamp indicating when the message was sent.

  1. Wait up to 600 ms for a response from the server. If no response is received within this time, record it as a timeout (packet lost).
  2. Report the following statistics:

o RTT for each successful ping.

Minimum RTT Maximum RTT , and Average RTT .

Percentage of packets acknowledged (i.e., received a response).

Total transmission time (from first sent packet to the last received response or timeout).

Jitter (variance in RTT between successive packets).

Example Command to Run the Client:

Java

$javac PingClient.java

$java PingClient

C

$gcc -o PingClient PingClient.c

$./PingClient

Python

$python3 PingClient.py

Where  is the IP address of the server (use 127.0.0.1 for localhost) and is the port number on which the server is listening.

Detailed Reporting:

The client must report the following at the end of execution:

  • RTTfor each ping request (or "timeout" if no response).
  • Minimum RTT, Maximum RTT, and Average RTT for the successful pings.
  • Percentage ofpackets acknowledged (i.e., how many responses were received out of 15 pings).
  • Total transmission time(time from sending the first ping to receiving the last response).
  • Jitter, which measures the variance in RTT values between successive pings. ( Jitter = Sum of (|RTT(n) - RTT(n-1)|) / (Number of packets received - 1))

Ping to 127.0.0.1, seq=10215, rtt=120 ms

Ping to 127.0.0.1, seq=10216, rtt=200 ms

Ping to 127.0.0.1, seq=10217, rtt=timeout

Ping to 127.0.0.1, seq=10218, rtt=150 ms

...

Total packets sent: 15

Packets acknowledged: 12

Packet loss: 20%

Minimum RTT: 50 ms, Maximum RTT: 200 ms, Average RTT: 120 ms

Total transmission time: 2000 ms

Jitter: 25 ms

Marking Criteria (5 Marks):

  1. Correct implementation of the ping protocol and handling of packet loss (2.5 marks):

o This includes correct handling of packet transmission, timeout, and managing packet loss as per the server's behavior.

  1. Accurate calculation and display of RTT for each successful ping (1.5 marks):

o RTT should be calculated accurately for every ping request that receives a response.

  1. Proper reporting of packet acknowledgment percentage, total transmission time, and jitter (1 mark):

o Includes accurate reporting of additional statistics like packet acknowledgment percentage, total transmission time, and jitter.

Resource created about a month ago, last modified 2 days ago.

 

标签:COMP3331,HTTP,trace,Programming,server,file,response,your
From: https://www.cnblogs.com/wx--codinghelp/p/18431952

相关文章

  • CS1112 Specific programming constructs
    CS1112Fall2024Project2dueWednesday9/25at11pmObjectivesCompletingthisprojectwillsolidifyyourunderstandingoffor-loops,while-loops,andnestedloops.Thecomputationalthemeofthisprojectissimulation,withproblem1usingrandomnessa......
  • COMP3331/9331 Computer Networks and Applications
    COMP3331/9331ComputerNetworksandApplicationsAssignmentforTerm3,2024BitTrickleFileSharing System1. Goal and Learning ObjectivesIn this assignment you will have the opportunity to implement BitTrickle, apermissioned,peer-to- pee......
  • 只有ip地址没有域名怎么申请https证书
    ​只有IP地址没有域名,如何申请HTTPS证书?在日常生活中,我们通常会为网站的域名申请HTTPS证书,以保护用户的数据安全。然而,有时候你可能需要为一个只有IP地址的服务或设备申请HTTPS证书。这种情况虽然不常见,但仍有可能出现在某些内部网络或特定的技术场景中。接下来,我们就来看看如何......
  • 7、http和https的区别?
    1,HTTP未加密的,安全性较差,HTTPS(SSL+HTTP)数据传输过程是加密的,安全性较好。2,使用HTTPS协议需要到CA机构申请证书,一般免费证书较少,因而需要一定费用。3,HTTP页面响应速度比HTTPS快,主要是因为HTTP使用TCP三次握手建立连接,客户端和服务器需要交换3个包,而HTTPS除了T......
  • http增删改查四种请求方式操纵数据库
    注意:在manage.py项目入口文件中的路由配置里,返回响应的return语句后面的代码不会执行,所以路由配置中每个模块代码要想都执行,不能出现return激活虚拟环境:venv(我的虚拟环境名称)\Scripts\activate启动项目:(命令行中先设置FLASK_APP环境变量指向manage.py,然后启动) pthon库O......
  • Vue.config.js中配置Proxy代理HTTPS
    Vue.config.js中配置Proxy代理HTTPS基本概念与作用为什么要使用HTTPS代理?示例一:基础HTTPS代理配置示例二:多环境代理配置示例三:忽略某些路径示例四:支持WebSocket代理示例五:高级配置实际开发中的使用技巧在开发基于Vue.js的应用时,经常会遇到前后端分离的情况,即前端应......
  • 即时通讯安全篇(十):为什么要用HTTPS?深入浅出,探密短连接的安全性
    3、写在前面说到HTTPS,那就得回到HTTP协议。对于HTTP协议,大家肯定都熟得不能再熟了。那么HTTPS和HTTP的区别大家了解吗?对于这个经典的面试题,大部分人会这么回答:1)HTTPS比HTTP多了一个S(Secure):也就是说HTTPS是安全版的HTTP;2)端口号不同:HTTP使用80端口,HTTPS使用443端口;3)加密算法:H......
  • HTTP和https的区别以及post和get请求的区别
    HTTP(HyperTextTransferProtocol)和HTTPS(HyperTextTransferProtocolSecure)都是用于在客户端(如浏览器)和服务器之间传输数据的协议。它们的主要区别在于数据的安全性。1.基本定义HTTP:是最基本的超文本传输协议,用于将网页和其他资源从服务器传输到客户端。但传输过程中,数据......
  • docker 配置代理访问Error response from daemon: Get “https://index.docker.io/v1/
    一、前言报错原因,docker访问不到外网。并且docker不能直接依赖操作系统环境的proxy,因此需要独立配置docker的proxy才能访问外网。问题描述dockersearchmysql出现以下报错:[root@localhost~]#dockersearchmysqlErrorresponsefromdaemon:Get"https://index.docke......
  • 《HTTP协议入门:简单易懂的6个步骤!》
    HTTP协议HTTP方法HTTP状态码HTTP头信息HTTP消息结构HTTP请求格式:请求行(requestline)、请求头部(header)、空行和请求数据四个部分组成,HTTP响应也由四个部分组成,分别是:状态行、消息报头、空行和响应正文。HTTP协议(HyperTextTransferProtocol,超文本传输协议)是因特网......