Question
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
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