0% found this document useful (0 votes)
7 views3 pages

TCP/IP File Transfer Client-Server Program

The document describes a Java program that implements a client-server architecture using TCP/IP sockets. The client requests a file by sending its name to the server, which then reads and sends the file's contents back to the client if the file exists. The code includes two classes, ContentClient and Server, with methods for establishing connections and handling file I/O operations.

Uploaded by

ravipandre29
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

TCP/IP File Transfer Client-Server Program

The document describes a Java program that implements a client-server architecture using TCP/IP sockets. The client requests a file by sending its name to the server, which then reads and sends the file's contents back to the client if the file exists. The code includes two classes, ContentClient and Server, with methods for establishing connections and handling file I/O operations.

Uploaded by

ravipandre29
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

}
}

You might also like