You are on page 1of 5

Marking guide Final Exam

2020/2021 Academic year


Bachelor of Technology
Option : IT- CCN
Course code/ Title: /Network Credit value …
programming protocols and standards 3…..
Duration: 13h-16h Date: 15/02/2021 Venue:
Course instructor(s) FOMAZOU TCHINDA
Instructions:
- The questions are not necessarily in order of difficulty. Read the entire exam first and then skip around as you see fit.
Make sure you get to all the problems.
- Read questions carefully. Understand a question before you start writing.
- Write down thoughts and intermediate steps to earn partial credit. Circle your final answer.
- If you have questions, ask.
- Relax. You are here to learn.
Section A
Question 1: 10 marks
1. Define the terms:
a. network programming: involves writing computer programs that enable processes to
communicate with each other across a computer network
b. socket: abstract concept and not an element of computer hardware.
c. multiplexing: handling of multiple connections simultaneously by a
single entity
d. protocol: rules governing the communication between devices 4mrks
2. Give the full meaning of the following:
a. HTTP: HyperText Transfer Protocol
b. FTP: File Transfer Protocol
c. RIP: Routing Information Protocol
d. OSPF: Open Shortest Path First
e. BGP: Border Gateway Protocol
f. URI: Uniform Resource Identifier
g. ICANN: Internet Corporation for Assigned Names and
Numbers
h. GUI: Graphical User Interface 4mrks
3. What is the difference between TCP and UDP? TCP is connection oriented while UDP is
connectionless 2mrks
4. What is the structure of an URL using BNF notation? 2mrks
<protocol>://<hostname>[:<port>][/<pathname>][/<filename>[#<section>]]
5. What are the key steps in reading writing to sockets? Network server programs are often
multithreaded. Explain what this means and why it is true.

Answer: A multi-threaded server creates a new thread to handle each client connection that it
accepts. A server program is generally designed to process connection requests from many clients.
It runs in an infinite loop in which it accepts a connection request and processes it. If the
processing takes a significant amount of time, it's not a good idea to make the other clients wait
while the current client is processed. The solution is for the server to make a new thread to handle
each client connection. The server can continue to accept other client connections even while the
first client is being serviced.

Page 1|5
6. What is the used of try and catch in java programming? Handle exception. Try capture the
exception and catch define the processes to perform in case the exception is appear while
running the program 3mrks
7. What is a deadlock? Give an illustration 2mrks

Question 2: MCQ 20 mark


b. URL
c. InetAddress
1. Which of these package contains classes
d. ContentHandler
and interfaces for networking?
7. Network programming in any language
a. java.io
definitely needs to deal with____________
b. java.util
and _______
c. java.net
a. User names; port numbers
d. java.network
b. IP addresses; link-layer address
2. Which of these is a protocol for breaking
c. IP addresses; port numbers
and sending packets to an address across a
d. None of the choices are correct
network?
8. In java, an IP address is defined as an
a. TCP/IP
object, the instance of ______________
b. DNS
class
c. Socket
a. InetAddress
d. Proxy Server
b. SocketAddress
3. How many ports of TCP/IP are reserved for
c. IPAddress
specific protocols?
d. None of the choices are correct.
a. 10
9. In java, which of the following statement is
b. 1024
true?
c. 2048
a. To create IPv4 address we must use
d. 512
Inet4Address class.
4. How many bits are in a single IP address?
b. To create IPv6 address we must use
a. 8
Inet6Address class.
b. 16
c. We can use InetAddress class to
c. 32
create both IPv4 and IPv6 addresses.
d. 64
d. None of the choices are correct.
5. Which of these is a full form of DNS?
10. The class used in java network
a. Data Network Service
programming for socket address is the
b. Data Name Service
________________ class.
c. Domain Network Service
a. InetAddres
d. Domain Name Service
b. SocketAddress
6. Which of these class is used to encapsulate
c. InetSocketAddress
IP address and DNS?
d. None of the choice are correct.
a. DatagramPacket
Page 2|5
11. A server in a client-server paradigm can be 16. The _____________ class is used to create
designed either as an __________ server or datagram packets
a_________ server. a. DatagramPacket
a. Asynchronous; concurrent b. DatagramSocket
b. Iterative; concurrent c. DatagramSocket or DatagramPacket.
c. Simultaneous; intermittent d. None of the choices are correct.
d. None of the choices are correct. 17. Java implementation of TCP uses
12. A concurrent server can serve _______________________ types of
___________________ socket objects.
a. One client at a time a. Only one
b. Only two clients simultaneously b. Only two
c. Several clients simultaneously c. Many types
d. None of the choices are correct. d. None of the choices are correct.
13. An iterative server handles 18. In java implementation of TCP, a client
__________________________ uses _______________; a server uses
a. One client at a time _________________.
b. Only two clients simultaneously a. ClientSocket object; ServerSocket object
c. Several clients simultaneously b. Socket object; ServerSocket object
d. None of the choices are correct. c. Socket object; ServerSocket object
14. Java implementation of UDP uses and Socket object
___________________________________ d. None of the choices are correct.
_____. 19. ________________ is responsible for
a. Only one type of socket objects establishing a connection.
b. Two types of socket objects a. Socket
c. Many types of socket objects b. ServerSocket
d. None of the choices are correct. c. ClientSocket
15. The DatagramSocket class is used to create d. None of the choices are correct.
sockets _______________________. 20. To create graphical interfaces in Java, you
a. In the UDP client should import which packages (choose all
b. In the UDP server that apply)?
c. In both the UDP client and UDP a. java.util
server b. java.awt.event
d. None of the choices are correct. c. javax.swing
d. java.io

Section B: Practice
Question 3: 10 marks
1. What is the IDE (name + JDK version) used in class for java network programming? Eclipse
JavaSE - 15 1mrk
2. Explain how to setup that environment. Install the JDK unzip eclipse zipped file lunch the
exe file having the eclipse logo (no need to install eclipse) 1mrk
3. Describe the process involved in writing a java class from edition to the execution. 3mrks
Create a new java project create a class in the created java project edit the code of the
class making sure that it contains a main classbuild and run.
4. Write a java class which ask for the name of and print out hello followed by that name. 5mrks
import java.util.Scanner;
public class sayHello {
Page 3|5
static String name;
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner keyboard = new Scanner(System.in);
System.out.println("We need your name for configuration purpose");
name = keyboard.next();
System.out.println("Hello "+ name);
}
}

Question 4: 20marks
Complete the following programs
1. To handle a client server communication:
a. Why is better to separate into two different processes? The client and the server have
different needs and therefore have to be treated separately
1mrk
b. Which one is to be handle first? The client or the server? Justify
i. the server because it is the one providing the services. The client simply send
queries 1.5mrks
2. What are the steps involved in the setting up of a server process using TCP socket? 2.5mrks
a. Create a ServerSocket object.
b. Put the server into a waiting state.
c. Set up input and output streams.
d. Send and receive data.
e. Close the connection (after completion of the dialogue).
3. Explain the following codes: 4mrks
a. Scanner input = new Scanner(link.getInputStream());
b. PrintWriter output = new PrintWriter(link.getOutputStream(),true);
They are used to setup input and output streams for the communication
4. Identify the step to which they belong. Step 3 Set up input and output streams
1mrk
5. Describe the steps involved in the settings of a client using TCP socket 4mrks
a. Establish a connection to the server: create a Socket object, supplying
b. Set up input and output streams
c. Send and receive data.
d. Close the connection
6. Modify the code below for it to match with the implementation of a sever using UDP socket
5mrks
7. What does the codes?
1mrk
//Server that echoes back client's messages.
//At end of dialogue, sends message indicating number of
//messages received. Uses datagrams.
import java.io.*;
import java.net.*;
public ____class___ UDPEchoServer{
private static final int PORT = 1234;
private static DatagramSocket datagramSocket;
private static DatagramPacket inPacket, outPacket;

Page 4|5
private static byte[] buffer;
public static void ____main_____(String[] args){
System.out.println("Opening port…\n");
try{
datagramSocket = new ______ DatagramSocket____________(PORT); //Step 1.
}
catch(SocketException sockEx){
System.out.println("Unable to open port!");
System.exit(1);
}
handleClient();
}
private static void handleClient(){
try{
String messageIn,messageOut;
int numMessages = 0;
InetAddress clientAddress = null;
int clientPort;
do{
buffer = new byte[____256____]; //Step 2.
inPacket =new ___ DatagramPacket____(buffer, buffer.length);//Step 3.
datagramSocket.receive(_____inPacket__________);//Step 4.
clientAddress = inPacket.getAddress();//Step 5.
clientPort = inPacket.______ getPort______________();//Step 5.
messageIn =new String(inPacket.getData(), 0,inPacket.getLength());
//Step 6.
System.out.println("Message received.");
numMessages++;
messageOut = "Message " + numMessages + ": " + messageIn;
outPacket = new DatagramPacket(messageOut.___ getBytes___(),
messageOut.length(),clientAddress,
clientPort); //Step 7.
_ datagramSocket__.send(outPacket); //Step 8.
}while (true);
}
catch(IOException ioEx){
ioEx.printStackTrace();
}
finally //If exception thrown, close connection.
{
System.out.println( "\n* Closing connection… *");
datagramSocket.__________close_______(); //Step 9.
}
}
}

GOOD LUCK

Page 5|5

You might also like