CompNetExamFall08

CompNetExamFall08 - EPFL-logo Computer Networks - Final...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
EPFL-logo Computer Networks - Final Exam Prof. J.-P. Hubaux and Dr. M. H. Manshaei January 27, 2009 Duration: 3:15 hours, closed book. Please write your answers on these sheets, at the end of each question; use extra sheets if necessary (put your name on them). You may write your answers in English or in French. The total number of points is 60. This document contains 18 pages. Student First name: Last name: Division: 2 Communication Systems 2 Computer Science 2 Other (mention it): . . . . . . . . . Year: 2 Bachelor Year 2 2 Bachelor Year 3 2 Other (mention it): . . . . . . . . . (answers to the questions are shown in italic and blue)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
1 Socket Programming (6 points) Consider the following Java program: 1: public class TCPServer { 2: public static void main(String argv[]) throws Exception { 3: String clientSentence; 4: String capitalizedSentence; 5: ServerSocket welcomeSocket = new ServerSocket(6789); 6: while(true) { 7: Socket connectionSocket = . .. 8: BufferedReader inFromClient = new BufferedReader( 9: new InputStreamReader(connectionSocket.getInputStream())); 10: DataOutputStream outToClient = new DataOutputStream( 11: connectionSocket.getOutputStream()); 12: clientSentence = inFromClient.readLine(); 13: capitalizedSentence = clientSentence.toUpperCase() + ’\n’; 14: outToClient.writeBytes(capitalizedSentence); 15: } 16: } 17: } Question 1: Complete line 7. 7: Socket connectionSocket = welcomeSocket.accept(); Question 2: Extend the server to print the IP address/port of every connecting client. Use line numbers to indicate which lines should be changed/removed and where new code should be added. We add the following line after line number 7: System.out.println("Incoming connection from IP: " + connectionSocket.getInetAddress() + " / port: " + connectionSocket.getPort()); Question 3: Assume that 3 different machines connect to the server (sequentially). As a result, how many Socket objects will be created by the server? How many TCP ports will be assigned to the server (not including the already assigned port 6789)? 3 Sockets objects are created. No additional port is assigned. 2
Background image of page 2
Question 4: Complete the code of the TCP client provided below. This client takes one command- line argument, sends it to the server, and displays the answer on the screen. Assume that the address of the server is compnet.epfl.ch . For simplicity, ignore exception handling. public class TCPClient { public static void main(String argv[]) throws Exception { String clientSentence = argv[0] + ’\n’; Socket connectionSocket = new Socket("compnet.epfl.ch", 6789); BufferedReader inFromServer = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); DataOutputStream outToServer = new DataOutputStream(connectionSocket.getOutputStream()); outToServer.writeBytes(capitalizedSentence); String capitalizedSentence = inFromServer.readLine();; System.out.println(capitalizedSentence); connectionSocket.close(); } } Question 5: Implement a program that lists ports between 4096 and 8192 that are assigned to UDP servers or clients (on the local machine). The information printed on the standard output should be of the following format: ”UDP Port # is busy”. Complete the code below.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 18

CompNetExamFall08 - EPFL-logo Computer Networks - Final...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online