Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is what I have so far.... package com.company; import java.io.*; import java.net.*; import java.util.*; public class Main { public static void main(String[] args) throws
This is what I have so far.... package com.company; import java.io.*; import java.net.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { if (args.length != 1) { System.out.println("Usage: java UDPClient2. Part I (85%): Write a client program and a server program to implement the following protocol on top of UDP. Client Program: 1. Display a message to ask the User to input the DNS or IP of the machine on which the Server Program runs. Display the following table on the standard output: Item ID Item Description 00001 New Inspiron 15 00002 New Inspiron 17 00003 New Inspiron 15R 00004 New Inspiron 15z Ultrabook 00005 XPS 14 Ultrabook 00006 New XPS 12 UltrabookXPS 3. Display a message on the standard output to ask the User to input an Item ID, and validate the user input. If the input is not a valid Item ID, ask the User to re-type it. 4. Once getting a valid item ID from the User, send a request including this Item ID (e.g., 00005 or 00005") to the Server program to ask for a quote, and record the local time right before sending such request. 5. Receive and interpret the response from the Server program, get the local time right after such response is received, and display the following information on the standard output, (e.g., if 00005 were provided by the User earlier on) Item ID Item Description Unit Price Inventory RTT of Query 00005 XPS 14 Ultrabook $999.99 261 ... ms where RTT of Query is the difference between the time in Steps 5 and 4 in millisecond. 6. Display a message on the standard output to ask the User whether to continue. If yes, repeat steps 2 through 5. Otherwise, close the socket and terminate the Client program. 2. Part I (85%): Write a client program and a server program to implement the following protocol on top of UDP. Client Program: 1. Display a message to ask the User to input the DNS or IP of the machine on which the Server Program runs. Display the following table on the standard output: Item ID Item Description 00001 New Inspiron 15 00002 New Inspiron 17 00003 New Inspiron 15R 00004 New Inspiron 15z Ultrabook 00005 XPS 14 Ultrabook 00006 New XPS 12 UltrabookXPS 3. Display a message on the standard output to ask the User to input an Item ID, and validate the user input. If the input is not a valid Item ID, ask the User to re-type it. 4. Once getting a valid item ID from the User, send a request including this Item ID (e.g., 00005 or 00005") to the Server program to ask for a quote, and record the local time right before sending such request. 5. Receive and interpret the response from the Server program, get the local time right after such response is received, and display the following information on the standard output, (e.g., if 00005 were provided by the User earlier on) Item ID Item Description Unit Price Inventory RTT of Query 00005 XPS 14 Ultrabook $999.99 261 ... ms where RTT of Query is the difference between the time in Steps 5 and 4 in millisecond. 6. Display a message on the standard output to ask the User whether to continue. If yes, repeat steps 2 through 5. Otherwise, close the socket and terminate the Client program"); return; } DatagramSocket udpSocket = new DatagramSocket(); BufferedReader sysIn = new BufferedReader(new InputStreamReader(System.in)); String fromServer; String fromUser; while ((fromUser =sysIn.readLine()) != null) { System.out.println("From Client: " + fromUser); InetAddress address = InetAddress.getByName(args[0]); byte[] buf = fromUser.getBytes(); DatagramPacket udpPacket = new DatagramPacket(buf, buf.length, address, 5300); udpSocket.send(udpPacket); byte[] buf2 = new byte[256]; DatagramPacket udpPacket2 = new DatagramPacket(buf2, buf2.length); udpSocket.receive(udpPacket2); fromServer = new String(udpPacket2.getData(),0,udpPacket2.getLength()); System.out.println("From Server: " + fromServer); if (fromUser.equals("Bye. ")) break; } udpSocket.close(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started