Q:

write a client-server program that displays the server machine date and time on the client machine

0

write a client-server program that displays the server machine date and time on the client machine

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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());
    }    
}

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now