write a client-server program that displays the server machine date and time on the client machine
Server code:
package com.mycompany.netserver; import java.net.*; import java.io.*; import java.util.*; class Server { public static void main(String args[]) throws Exception { ServerSocket s=new ServerSocket(5217); while(true) { System.out.println("Waiting For a Connection ..."); Socket soc=s.accept(); DataOutputStream out=new DataOutputStream(soc.getOutputStream()); out.writeBytes("Server Date is : " + (new Date()).toString() + "\n"); out.close(); soc.close(); } } }
Client code:
package com.mycompany.netclient; import java.io.*; import java.net.*; class Client { public static void main(String args[]) throws Exception { Socket soc=new Socket(InetAddress.getLocalHost(),5217); BufferedReader in=new BufferedReader(new InputStreamReader(soc.getInputStream() )); System.out.println(in.readLine()); } }
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Server code:
Client code: