Republic of Yemen Second Semester/Final Exam
University of Shaba Region Date: Thu, May, 25, 2023
Faculty of IT & CS Time duration: 2 h
Module Title: Network Programming
المجموع كتابة المجموع رقما 6س 5س 4س 3س 2س 1س رقم السؤال
60 15 12 12 8 5 8 درجة السؤال
ستون درجة الدرجة المستحقة
.................................:القسم..............................................................................:اسم الطالب
Answer all of the following questions
Question 1 (8 Marks)
Assume you have our client on one host and the server on another host.
a) Suppose you run the a TCP client without starting the server. What happen exactly and why?
b) Suppose you run the a UDP client without starting a UDP server. What is different from the case of
TCP and why?
c) What happens with TCP and UDP if you start the server after the client but before typing any input?
d) What happens if you connect the TCP client to a web server running on port 80 instead of the case
server?
Good luck Page 1 of 5 Dr. Maqbol Qaid Alkamel
Question 2 (5 Marks)
A thread is placeholder information associated with a single use of a program that can handle multiple
concurrent users. From the program's point-of-view, a thread is the information needed to serve one
individual user or a particular service request. If multiple users are using the program or concurrent requests
from other programs occur, a thread is created and maintained for each of them. The thread allows a
program to know which user is being served as the program alternately gets re-entered on behalf of different
users.
Create the code that display the message ‘Network Programming’ five times and the other message output
integers 1–5.
Good luck Page 2 of 5 Dr. Maqbol Qaid Alkamel
Question 3 (8 Marks)
State whether each of the following is true or false: حدد ما إذا كان كل مما يلي صحيحا أم خطأ
1. A port is a logical connection to a computer (as opposed to a physical connection) and is identified by
a number in the range 1–1023. ( )
2. Application programs wishing to use ports for non-standard services should avoid using port numbers
1–1023. ( )
3. The port number for server and client programs must not be the same. ( )
4. A URL (Uniform Resource Locator) is a unique identifier for any resource located on the Internet.( )
5. UDP resends a packet if it fails to arrive or there is some other error and reassembles the packets in the
correct sequence at the receiving end. ( )
6. There is a fundamental and important limitation associated with all the server programs. For example,
they can handle only one connection at a time. One of the solutions is to use a multithreaded server.( )
7. An atomic operation (i.e., one that could not be split up into simpler operations). ( )
8. The getContent() method is a way to download data referenced by a URL. ( )
Question 4 (12Marks)
Let's say we have the following link:
"https://www.google.com/search?q=network+programming+in+java&sxsrf=ALiCzsYjNj4rvozJ5npBui_
hOxHPtTbLhg%3A1656354799581#source=hp&ei=7_e5Y".
Based on what you have studied, write a program that will print the information that can be obtained.
(Hint: using URL and URI Classes).
Good luck Page 3 of 5 Dr. Maqbol Qaid Alkamel
Question5 (12 Marks)
Write a program for a client server model that sends and receives messages using TCP protocol.
public class TCPServer { public class TCPClient {
} }
Question 6 (15 Marks)
What are the returns/works of the following methods?
1. public String getHostName() //InetAddress Class
2. public String getHostAddress() //InetAddress Class
Good luck Page 4 of 5 Dr. Maqbol Qaid Alkamel
3. public final InputStream openStream() //URL Class
4. public URLConnection openConnection() //URL Class
5. public final Object getContent() //URL Class
6. URLEncoder.encode()
7. equals() and hashCode()
8. URLDecoder.decode()
Good luck Page 5 of 5 Dr. Maqbol Qaid Alkamel