Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

EBU5042 Alternative Assessment (Odd Semester - Paper B)

Joint Programme Assessments 2021/22

EBU5042 Advanced Network Programming

Instructions

This is an open-book assessment, which should be completed within 2 hours. You MUST submit your answers within 3 hours from the assessment being released.

You MUST complete the assessment on your own, without consulting any other person. You MAY NOT check your answers with any other person.

You can refer to textbooks, notes and online materials to facilitate your working, if you provide a direct quote, or copy a diagram or chart, you must cite the source.

 

Before you start the assessment

1) Read the questions thoroughly and understand them.

2) Ensure you have all the resources you require to complete and upload the final assessment.

3) If you require any assistance, raise the issue via the messaging section of this assessment on QMPlus, immediately.

 

During the assessment session

1) Use the supplied answer sheet document to enter your answers.   Start on a new page for each question.  Make sure it is clear which question number you are answering.

2) Type your answers in the supplied answer sheet; hand-written equations or sketches can be                incorporated into the answer sheet. Please save your work at least every 15 minutes so that you do not risk losing it.

3) When completed answering all questions, perform a word count and list the number of words on the answer sheet, then save the file as pdf before uploading, only pdf will be accepted, any other file

format will not be accepted.

4) Your submission must be your own work, and you must ensure that you do not break any of the rules in the Academic Misconduct Policy.

 

Submitting the Assessment

1) You will have 3 hours from the start of the scheduled assessment time – do not leave submissions too close to the deadline. NO late submission will be accepted, no exceptions.

2) Make sure you upload and submit the final version before the deadline.

3) Please be aware that submissions will be subject to review, including but not limited to plagiarism detection software.

If you have any problems relating to access or submitting during the assessment period, please contact the email ([email protected]), state the module code in the subject, and clearly state your name

and student ID and any issues you are experiencing. You must use either @qmul.ac.uk or       @bupt.edu.cn email address. Requests from external email addresses will not be processed.


 

Question 1

a) This question is about threads.

i)   Describe in your own words the relationship between the stop()start(), and run() methods. Your answer must include a brief explanation of what each of these methods does and how they are used together.

ii)  Imagine you are working with a legacy system which uses the stop() method. Describe how you should deal with such a situation.

iii) Imagine you have just created a thread in your code and you started the thread by calling the start() method. Under this scenario, indicate:

a.   Can you change the thread to a daemon?

b.   Considering your answer to part a., does that depend on the state the thread is in and what exception will be thrown, if any?

iv) This question is about the join()wait(), and notify() methods. In your own words, briefly describe the benefit of using wait() and notify(), instead of the join() method.

 

b) This question is about HTML. You are asked to write the HTML code to generate the webpage shown in Figure 1Note: You should pay particular attention to the options available with the radio buttons and checkboxes.

 

Figure 1

 

a) Consider the server code in

 

Figure 2

(lines numbered 1-25) and answer the questions below:

[12 marks]

01. import java.io.*;

02. import java.net.*;

03. public class Server {

public static void main(String[] args) {

System.out.println("Starting server...");

Socket serverSocket = null;

try {

serverSocket = new Socket(4646);

while(true) {

Socket socket = serverSocket.accept_connection();

System.out.println ("New connection established.");

OutputStreamWriter os = new

OutputStreamWriter(socket.getOutputStream()); BufferedWriter wr = new BufferedWriter(os);

PrintWriter pwr = new PrintWriter(wr, true);

pwr.println("Connection established.");

serverSocket.close();

}

}

catch(Exception e) { e.printStackTrace(); }

finally {

try { serverSocket.close(); }

catch(IOException e) { e.printStackTrace(); }

}

}

Figure 2

i)   The code ofthe server contains some errors: list these errors and suggest how to correct them.

(4 marks)

ii)  Assume that the code has been corrected, the server is running, and a client attempts to establish a connection with it on port 4646: explain what would happen on the server side.

iii) Assume again that the code has been corrected and the server is running, but this time a client attempts to establish a connection on port 6464. What would happen? Would this cause an exception to be raised on the server?

iv) Is this server capable of handling more than one client at the same time? Justify your answer.

(2 marks)


b) Answer the following questions about HTTP:

i)   Consider the HTTP response shown inFigure 3and explain the meaning ofthe lines highlighted in bold.

HTTP/1.1    404 Not Found

Server: Apache/2.2.14

Date: Fri, 4 June 2021 12:01:05 GMT

Content-Type: text/html

Content-Length: 169

Connection: keep-alive

<html>

<head><title>404 Not Found</title></head> <body bgcolor="white">

<center><h1>404 Not Found</h1></center> <hr><center>nginx/0.8.54</center>       </body>

</html>

Figure 3

ii)  Explain how the Cookie HTTP request header and the Set-Cookie HTTP response header are used to handle cookies in client-server communications.

iii) Your browser makes an HTTP  1.1 request to a webpage that contains  3 files: index.htmlimage_1.jpg, and image_2.jpg. Assume the connection is persistent. Answer the following questions:

c.   How many TCP connections are established to transfer the files?

d.   Without pipelining, how many GET requests are sent from the client to the server?

e.   Ifpipelining is used, how many GET requests are sent from the client to the server?

 

Question 3

a) Fill in the SIX (6) gaps in the sentences below related to JavaScript. You are only required to write down what the blanks marked 1 to 6 correspond to:

“A _____1_____ is a reusable piece ofJavaScript code that performs a common task.

The           2           function writes text to the HTML document.

onChange is an example of an _____3_____ in JavaScript.

A JavaScript _____4_____ is a data structure that allows you to store a list of items.     The _____5_____ function is used to convert a string to an integer value in JavaScript.

JavaScript executes in the _____6_____ on the client-side.”

b) This question requires you to write the code for a Java servlet called EchoServlet. This servlet will

When accessed, the servlet should then reply with an HTML document (i.e., text/html) with the value of the echo parameter contained with the document, such that it will be printed in the browser

screen.

[9 marks]

c) Figure 4presents an HTML document. It is saved inside a file called FavouriteAnimal.html. The webpage asks users to indicate their favourite animal from a set of possible options. This question will involve writing the JavaScript code to embed inside this document.

<html>

<head>

<title>Select your favourite animal!</title> <script>

// CODE TO BE ADDED HERE: function pick()

</script>

</head>

<body>

<form name="animalSelection">

<h2>Please select your favourite animal:</h2> <select name="fav">

<option selected></option>

<option>Cat</option>

<option>Dog</option>

<option>Fish</option>

<option>Rabbit</option>

</select>

<input type="submit" value="Select"/> </form>

</body>

</html>

Figure 4

i)   Write the code for the JavaScript function pick(), which should do the following things when the user clicks the submit button:

1.   Your JavaScript code should check if the user has selected a favourite animal. If that is not the case, then the function should return false and an alert box should be generated with the message “You forgot to select a favourite animal!” .

2.   Your JavaScript code should check if the user has already stipulated their favourite animal in a previous browser session. Ifthe user had already selected a favourite, then the function must return false and an alert box should be generated with the message “You have already selected your favourite animal!” .

3.   Ifthe first two checks are satisfied, then the function pick() returns true and another webpage called SelectionSuccessful.html should be loaded. Note: You are not required to write the code for this second webpage.

ii)  Let us now assume we have the code inFigure 4, together with the code written in part i); answer the two sub-questions below:

a.    State what will happen ifyou click the submit button; briefly explain your answer.

b.   Modify the HTML code, so that user data collected in the HTML document can be sent to

the webpage SelectionSuccessful.html, after successfully validating the user data. Note: You are not required to rewrite the entire webpage’s code in the answer box.

(4 marks)

 

Question 4

a) Write the code for a properly formed JavaBean class called StudentDetails, which has the properties: classRep  (a  boolean  to  indicate  whether  a  student  is  a  class  representative)  and  studentID (representing a student’s BUPT number).

Then write the code for a JSP page that uses the StudentDetails JavaBean and sets the classRep property to true using an appropriate JSP action; the modified value ofclassRep should be displayed by the JSP page.

Note: You can assume that session handling is not being applied.

b) Consider the code fragment of a Java servlet given inFigure 5. You can assume that Lecturer is a JavaBean class defined elsewhere, with a String attribute called name.

Lecturer myJBean = (Lectures)request.getAttribute("myJBean"); if (myJBean == null) {

myJBean = new Lecturer();

request.setAttribute("myJBean", myJBean);

}

Figure 5

i)   Write equivalent JSP code (in terms of functionality) for the code inFigure 5.

ii)  Write a JSP statement that retrieves the currently stored value of name in the Lecturer JavaBean class. Note: Your answer must make use of the code written in part i).

(1 mark)

c) Fill in the SIXTEEN (16) gaps in the sentences below about MVC. You are only required to write down what the blanks marked 1 to 16 correspond to.

“In a web application, ____1____ programs are useful to use when the application requires a lot of ____2____ to be done; however, using them to ____3____ HTML code can lead to ____4____.       On the other hand, ____5____ allow the programmer to ____6____ much of the ____7____ from the ____8____.

In such a scenario, we have web development that can be considered to follow an ____9____ approach  if we  also  use  ____10____  to  ____11____  and  store  any  required  data  between ____12____. The ____13____ then acts as a ____14____, while ____15____ ____16____ any required responses.”