This document is the final exam for the course COSC 313 TCP/IP Programming, administered by instructor Nizeyimana Pierre Celestin. It consists of 7 questions that cover various aspects of TCP/IP programming, including client-server communication, network interfaces, and error handling in Java. Students are required to attempt all questions within a duration of 1 hour and 30 minutes.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
12 views1 page
TCP2 Final Exam_TCPIP and solution
This document is the final exam for the course COSC 313 TCP/IP Programming, administered by instructor Nizeyimana Pierre Celestin. It consists of 7 questions that cover various aspects of TCP/IP programming, including client-server communication, network interfaces, and error handling in Java. Students are required to attempt all questions within a duration of 1 hour and 30 minutes.
INSTRUCTIONS: This paper comprises 7 questions Attempt all questions
TCP/IP Programming _Theory / 40 marks
Question 1/ 5 marks Question 5 / 5 marks
If “dis” and “dout” are respectively the “DataInputStream” and The codes below print all the IP v4 addresses that are the “DataOutputStream” of a “Chat Server”, explain what is active on the local host machine. wrong with line 6 in the codes below: Enumeration<NetworkInterface> netif1 = while(true) { NetworkInterface.getNetworkInterfaces(); String str1 = dis.readUTF(); for (NetworkInterface netif2 : Collections.list(netif1)) { System.out.println ("Client says:" + str1); if(netif2.isUp()&& ! netif2.isLoopback()) System.out.println ("Type a response to the client...."); for (InterfaceAddress String msg1 = scan.nextLine(); Inet:netif2.getInterfaceAddresses()) dout.readUTF(msg1); if(Inet.getAddress() instanceof Inet4Address) dout.flush(); System.out.println(Inet.getAddress());} } Change line4 and line 7 so that the output is: Question2/5 marks “127.255.255.255” The following are codes of a client requesting “today’s date” Question 6 / 5 marks from a server and “dis” and “dout” are respectively the Refer to the codes above, which line can you “DataInputStream” and the “DataOutputStream”. Reorganize changed so that the codes print both IPv4 and IPV6 the lines properly on the server side. that are active. How would you change it? Client Question 7 / 5 marks String str1 = "What is today's date ?"; The codes below are supposed to give the same dout.writeUTF (str1); output as the codes on question 4 above. String str2 = dis.readUTF(); Enumeration<NetworkInterface> netif1 = System.out.println (str2); NetworkInterface.getNetworkInterfaces(); Server for (NetworkInterface netif2 : Collections.list(netif1)) { dout.writeUTF(date.toString()); if(nwIf.isUp()&& !nwIf.isLoopback()) System.out.println (str1); for(InetAddress inetad : nwIf.getInetAddre sses()) String str1 = dis.readUTF(); if(inetad instanceof Inet4Address) Date date = new Date (); System.out.println(inetad);} Question 3 / 5 marks But when compiled they give following error The host below is disconnected from internet, explain why the message showing on line 5 codes print “8” as output. required: array or java.lang.Iterable NetworkInterface add = found: Enumeration<InetAddress> NetworkInterface.getByInetAddress(InetAddress.getLocalHost()); Why and how should it be fixed? List<InterfaceAddress> itadd = add.getInterfaceAddresses(); Question 8 / 5 marks System.out.println(itdd.get(0).getNetworkPrefixLength()); The codes below implement an echo server. Explain. Question 4 / 5 marks while(true) { If the last line of the above codes is changed to String str1 = dis.readUTF(); System.out.println(itdd.get(0).getAddress()); dout.writeUTF(str1); What would be the output? dout.flush();} 11111111111111