Program7: Using TCP/IP sockets, write a client – server program to make the client send the file
name and to make the server send back the contents of the requested file if present.
[Link]
import [Link].*;
import [Link];
import [Link].*;
public class ContentClient
public static void main(String args[])throws IOException
Socket sock=new Socket("localhost",4000);
[Link]("enter the filename");
Scanner sc=new Scanner([Link]);
String fname=[Link]();
OutputStream ostream=[Link]();
PrintWriter pwriter=new PrintWriter(ostream,true);
[Link](fname);
InputStream istream=[Link]();
Scanner sc1=new Scanner(istream);
String str;
while([Link]())
str=[Link]();
[Link](str);
[Link]();
[Link]();
[Link]();
}
[Link]
import [Link].*;
import [Link].*;
import [Link];
import [Link];
public class Server
{public static void main(String args[])throws IOException,FileNotFoundException{
ServerSocket serverSocket = new ServerSocket();
[Link](true);
[Link](new InetSocketAddress(4000));
[Link]("Server ready for connection");
Socket sock=[Link]();
[Link]("connection was successfull");
InputStream istream=[Link]();
Scanner sc=new Scanner([Link]);
String fname=[Link]();
Scanner sc1=new Scanner(new FileReader(fname));
OutputStream ostream=[Link]();
PrintWriter pwriter=new PrintWriter(ostream,true);
String str;
while([Link]())
str=[Link]();
[Link](str);
[Link]("file content sent successfully");
[Link](); [Link]();
[Link](); [Link]();
[Link]();
}
}