Question: Java Question. Implement a client-server program in which the client will print the date and time given by the server. Two classes should be implemented:

Java Question. Implement a client-server program in which the client will print the date and time given by the server. Two classes should be implemented: DateClient and DateServer. The DateServer simply prints new Date().toString() whenever it accepts a connection and then closes the socket using starting program given.

import java.io.IOException; public class ClientServerDemo { public static void main(String[] args) throws InterruptedException { // start the server class ServerRunnable implements Runnable { public void run() { try { DateServer.main(new String[] {}); } catch (IOException ex) { ex.printStackTrace(); } } } Thread t1 = new Thread(new ServerRunnable()); t1.start(); // start the client class ClientRunnable implements Runnable { public void run() { try { DateClient.main(new String[] {}); } catch (IOException ex) { ex.printStackTrace(); } } } Thread t2 = new Thread(new ClientRunnable()); t2.start(); t2.join(); System.exit(0); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!