Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a server program to implement the following protocol on top of UDP. This is what I have so far... package com.company; import java.io.*; import

image text in transcribed

Write a server program to implement the following protocol on top of UDP.

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{ DatagramSocket udpServerSocket = null; BufferedReader in = null; DatagramPacket udpPacket = null, udpPacket2 = null; String fromClient = null, toClient = null; boolean morePackets = true; byte[] buf = new byte[256]; udpServerSocket = new DatagramSocket(5300); while (morePackets){ try { udpPacket = new DatagramPacket(buf, buf.length); udpServerSocket.receive(udpPacket); fromClient = new String(udpPacket.getData(),0,udpPacket.getLength()); toClient = fromClient.toUpperCase(); InetAddress address = udpPacket.getAddress(); int port = udpPacket.getPort(); byte[] buf2 = toClient.getBytes(); udpPacket2 = new DatagramPacket(buf2, buf2.length,address,port); udpServerSocket.send(udpPacket2); } catch (IOException e){ e.printStackTrace(); morePackets = false; } } udpServerSocket.close(); } } 
Server Program: 1. Maintain the following information using an appropriate data structure of your choice (i.e., an array of a Class you defined). You do not have to place it in a file although you certainly can if you like. Item ID Item Description Unit Price Inventory 00001 New Inspiron 15 $379.99 157 00002 New Inspiron 17 $449.99 128 00003 New Inspiron 15R $549.99 202 00004 New Inspiron 15z Ultrabook $749.99 315 00005 XPS 14 Ultrabook $999.99 261 00006 New XPS 12 Ultrabook XPS $1199.99 178 2. Wait for receiving a packet from a Client. 3. Once a packet is received from a Client, retrieve the information relevant to the requested Item ID from the data structure you used in Step 1 and send back such information to the Client. 4. Repeat Steps 2 and 3 infinitely until an exception is caught. 5. Close the datagram socket. Server Program: 1. Maintain the following information using an appropriate data structure of your choice (i.e., an array of a Class you defined). You do not have to place it in a file although you certainly can if you like. Item ID Item Description Unit Price Inventory 00001 New Inspiron 15 $379.99 157 00002 New Inspiron 17 $449.99 128 00003 New Inspiron 15R $549.99 202 00004 New Inspiron 15z Ultrabook $749.99 315 00005 XPS 14 Ultrabook $999.99 261 00006 New XPS 12 Ultrabook XPS $1199.99 178 2. Wait for receiving a packet from a Client. 3. Once a packet is received from a Client, retrieve the information relevant to the requested Item ID from the data structure you used in Step 1 and send back such information to the Client. 4. Repeat Steps 2 and 3 infinitely until an exception is caught. 5. Close the datagram socket

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke, David Auer

11th Edition

B003Y7CIBU, 978-0132302678

More Books

Students also viewed these Databases questions

Question

What do you mean by dual mode operation?

Answered: 1 week ago

Question

Explain the difference between `==` and `===` in JavaScript.

Answered: 1 week ago