Program 6- TCP and IP
Program 6- TCP and IP
file name and to make the server send back the contents of the requested file if present.
This server program listens on a specified port and waits for the client to send the name of the
file. If the file exists on the server, it sends the file contents back to the client.
Program:-
import java.io.*;
import java.net.*;
System.out.println("Client connected.");
String line;
writer.println(line);
} catch (IOException e) {
else
catch (IOException e)
}
}
The client connects to the server, sends the file name, and then reads the response from the
server (which is the contents of the requested file, or an error message if the file isn't found).
Program:-
import java.io.*;
import java.net.*;
writer.println(fileName);
String line;
if (line.equals("EOF")) {
} catch (IOException e) {
Output:-
************** END******************************************