Contact us - +12567847275

Computer Science

Suppose you are the attacker who has got hold of the complied
SimpleWebServer.class. Describe an attack such that, after
SimpleWebServer is re-started (e.g., because of an exception by
another attack), the functionality in (3) is disabled.

Simple web

public class SimpleWebServer {

/* Run the HTTP server on this TCP port.
private static final int PORT = 8081;

/* The socket used to process incoming
connections from web clients */
private static ServerSocket dServerSocket;

public SimpleWebServer() throws Exception
dServerSocket = new

public void run() throws Exception {
while (true) {
/* wait
for a connection from a client */
Socket s =

/* then
process the client’s request */

* Reads the HTTP request from the client, and
responds with the file the user
* requested or a HTTP error code.
public void processRequest(Socket s) throws
Exception {
/* used to read data from the
client */
BufferedReader br = new
BufferedReader(new InputStreamReader(s.getInputStream()));

/* used to write data to
the client */
OutputStreamWriter osw = new

/* read the HTTP request
from the client */
String request =

String command =
String pathname = null;

/* parse the HTTP request
StringTokenizer st = new
StringTokenizer(request, ” “);

command =
pathname =

if (command.equals(“GET”))
* if the
request is a GET try to respond with the file the user is
System.out.println(“Path name: ” + pathname);
serveFile(osw, pathname);
} else {
* if the
request is a NOT a GET, return an error saying this server does
implement the requested command
osw.write(“HTTP/1.0 501 Not Implementednn”);

/* close the connection to
the client */

public void serveFile(OutputStreamWriter osw,
String pathname) throws Exception {
FileReader fr = null;
int c = -1;
StringBuffer sb = new

/* remove the initial
slash at the beginning of the pathname in the request */
if (pathname.charAt(0) ==
pathname =

* if there was no filename
specified by the client, serve the “index.html” file
pathname =

/* try to open file
specified by pathname */
try {
System.out.println(“Path name: “+pathname);
fr = new
c =;
} catch (Exception e) {
/* if the
file is not found,return the appropriate HTTP response code
osw.write(“HTTP/1.0 404 Not Foundnn”);

* if the requested file can
be successfully opened and read, then return an OK
* response code and send the
contents of the file
osw.write(“HTTP/1.0 200
while (c != -1) {
sb.append((char) c);
c =;

/* This method is called when the program is
run from the command line. */
public static void main(String argv[]) throws
Exception {
/* Create a SimpleWebServer
object, and run it */
SimpleWebServer sws = new



15% off for this assignment.

Our Prices Start at $11.99. As Our First Client, Use Coupon Code GET15 to claim 15% Discount This Month!!

Why US?

100% Confidentiality

Information about customers is confidential and never disclosed to third parties.

Timely Delivery

No missed deadlines – 97% of assignments are completed in time.

Original Writing

We complete all papers from scratch. You can get a plagiarism report.

Money Back

If you are convinced that our writer has not followed your requirements, feel free to ask for a refund.