Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the daytime protocol server using UDP program below that is running at host time.om, write the daytime protocol client using UDP. import java.net.*; import

Given the daytime protocol server using UDP program below that is running at host time.om, write the daytime protocol client using UDP.

import java.net.*;

import java.util.Date;

import java.util.logging.*;

import java.io.*;

public class DaytimeUDPServer {

private final static int PORT = 13;

private final static Logger audit = Logger.getLogger("requests");

private final static Logger errors = Logger.getLogger("errors");

public static void main(String[] args) {

try (DatagramSocket socket = new DatagramSocket(PORT)) {

while (true) {

try {

DatagramPacket request = new DatagramPacket(new byte[1024], 1024);

socket.receive(request);

String daytime = new Date().toString();

byte[] data = daytime.getBytes("US-ASCII");

DatagramPacket response = new DatagramPacket(data, data.length,

request.getAddress(), request.getPort());

socket.send(response);

audit.info(daytime + " " + request.getAddress());

} catch (IOException | RuntimeException ex) {

errors.log(Level.SEVERE, ex.getMessage(), ex);

}

}

} catch (IOException ex) {

errors.log(Level.SEVERE, ex.getMessage(), ex);

}

}

}

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_2

Step: 3

blur-text-image_step3

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

Students also viewed these Databases questions