Вы находитесь на странице: 1из 5

CONFIDENTIAL

CS/JAN 2012/ITT440

UNIVERSITI TEKNOLOGI MARA FINAL EXAMINATION

COURSE COURSE CODE EXAMINATION TIME

NETWORK PROGRAMMING ITT440 JANUARY 2012 3 HOURS

INSTRUCTIONS TO CANDIDATES 1. 2. This question paper consists of three (3) questions. Answer ALL questions in the Answer Booklet. Start each answer on a new page. Do not bring any material into the examination room unless permission is given by the invigilator. Please check to make sure that this examination pack consists of: i) ii) the Question Paper an Answer Booklet - provided by the Faculty

DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SO


This examination paper consists of 5 printed pages
Hak Cipta Universiti Teknologi MARA CONFIDENTIAL

CONFIDENTIAL

CS/JAN 2012/ITT440

QUESTION 1 Consider the following Java program: l 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 public class TCPServer { public static void main(String argv[]) " throws Exception { String clientSentence; String capitalizedSentence; ServerSocket welcomeSocket = new ServerSocket(6789); while(true) { Socket connectionSocket = ... BufferedReader inFromClient = new BufferedReader( new InputStreamReader(connectionSocket.getlnputStreamO)) DataOutputStream outToClient = new DataOutputStream( connectionSocket.getOutputStream() ) ; clientSentence = inFromClient.readLine(); capitalizedSentence = clientSentence.toUpperCase() + '\n' outToClient.writeBytes(capitalizedSentence);

}
}

}
(4 marks)

a) Please complete line 7 b) Extend the above TCPServer class so that it will print every address or port of every connecting client. Please use line number to indicate which line should be change or remove and where new code should be added. (6 marks) c) Assume that 3 different machines connect to the server (sequentially), i) How many Socket objects will be created by the server? ii) How many TCP ports will be assigned to the server, not including the already assigned port 6789? (4 marks) d) Complete the code of the TCP client provided below. This client takes a string from the command-line argument, sends it to the server, and displays the answer from the server on the screen. Assume that the address of the server is netprog.uitm.edu.my. For simplicity, ignore exception handling. Public class TCPClient { Public static void main(String argv[]) throws Exception { String clientSentence = argv[0] + ' \n';

(14 marks)
Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/JAN 2012/ITT440

e) The code below is an incomplete program that will list ports between 4096 and 8192 that are assigned to UDP servers or clients on the local machine. Complete the code so that the program will print the sentence "UDP Port # is being used" on the standard output. public class UDPscanner { public static void main (String[] args) { for (int i = 4096; i < 8192; i++){

} } } (10 marks) QUESTION 2


Consider the following clip of code for a UDP server and client: Client:

for(;;) { sendto(sockfd, }
Server:

...

);

for(;;) { recvfrom(sockfd, }

...

);

a) Explain what happen if we put a printf statement in the client code after the sendto statement within the loop? Does this change the percentage of received packets at the server side? (4 marks) b) Explain what happen if we put a printf statement in the server code after each recvfrom statement? Does this change the percentage of received packets at the server side? (4 marks)

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL c) Consider the following program code:

CS/JAN 2012/ITT440

Shared struct definition between client and server: struct args { long argl; long arg2; };

struct result { long sum;


}; Client code: void client (int sockfd) struct args a; struct result r; char sendline[400];

// initialize struct args variables. a.argl = 10023; a.arg2 = 32121; // write to server using sockfd write(sockfd, &args, sizeof(args)); if (read(sockfd, &result, sizeof(result)) ! = 0 ) printf("sum = %ld\n" result.sum);

}
Server Code: void server (int sockfd) { struct args a; struct result r; ssize_t n;

for ( ; { ;)
if ( (n = read(sockfd, &args, sizeof(args))) = = 0) return;

}
result.sum = a.argl + a.arg2; write(sockfd, &result, sizeof(result));

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/JAN 2012/ITT440

Consider the fact that the socket was properly established and structures were properly initialized and also the code was properly compiled. i) EXPLAIN TWO(2) potential problems that can be caused by the above code. (8 marks)

ii) EXPLAIN how those problems can be solved. (4 marks) iii) If the same program is written in Java, will the same problem persist or not? If so, why? (4 marks) QUESTION 3 a) EXPLAIN how OS such as Unix or Linux creates a new process. (3 marks) b) WRITE an explanation on the following function calls by specifying the syntax, operation and necessity. i) ii) iii) iv) v) vi) listen inet_pton setsockopt recvfrom bind socket (18 marks) c) COMPARE differences and/or similarities that exists between iterative server and concurrent server. (8 marks) d) There are 3 methods in which a program can transfer a binary data across a network, LIST and EXPLAIN the three methods. (9 marks)

END OF QUESTION PAPER

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

Вам также может понравиться