mirror of
https://github.com/RustyRaptor/Programs.git
synced 2026-12-03 15:45:21 -07:00
resized images and adjusted code
This commit is contained in:
1 parent
e94176036d
commit
1f6c9cdd88
8 files changed
+103
-37
No files matched your search
+12
-10
@@ -1,12 +1,16 @@
|
||||
<project name="Hello World Project" default="jar">
|
||||
<target name="compile">
|
||||
<mkdir dir="build/classes"/>
|
||||
<javac srcdir="src" destdir="build/classes"/>
|
||||
<project name="Hello World Project" default="run" basedir=".">
|
||||
<target name="clean">
|
||||
<delete dir="bin"/>
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="clean">
|
||||
<mkdir dir="bin/classes"/>
|
||||
<javac srcdir="src" destdir="bin/classes"/>
|
||||
</target>
|
||||
|
||||
<target name="jar" depends="compile">
|
||||
<mkdir dir="build/jar"/>
|
||||
<jar destfile="build/jar/HelloWorld.jar" basedir="build/classes">
|
||||
<mkdir dir="bin/jar"/>
|
||||
<jar destfile="bin/jar/SimpleWebServer.jar" basedir="bin/classes">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="edu.nmsu.cs.webserver.WebServer"/>
|
||||
</manifest>
|
||||
@@ -14,11 +18,9 @@
|
||||
</target>
|
||||
|
||||
<target name="run" depends="jar">
|
||||
<java jar="build/jar/HelloWorld.jar" fork="true"/>
|
||||
<java jar="bin/jar/SimpleWebServer.jar" fork="true" dir="./www/"/>
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="build"/>
|
||||
</target>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -18,27 +18,24 @@ import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
|
||||
public class WebServer {
|
||||
private ServerSocket socket;
|
||||
|
||||
private boolean running;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
**/
|
||||
private WebServer() {
|
||||
running = false;
|
||||
boolean running = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Web server starting point. This method does not return until the server is finished, so perhaps
|
||||
* it should be named "runServer" or something like that.
|
||||
*
|
||||
* @param port
|
||||
* is the TCP port number to accept connections on
|
||||
* @param port is the TCP port number to accept connections on
|
||||
**/
|
||||
private boolean start(int port) {
|
||||
Socket workerSocket;
|
||||
WebWorker worker;
|
||||
ServerSocket socket;
|
||||
try {
|
||||
socket = new ServerSocket(port);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -20,12 +20,6 @@ package edu.nmsu.cs.webserver;
|
||||
* @author Jon Cook, Ph.D.
|
||||
**/
|
||||
|
||||
import com.sun.imageio.plugins.gif.GIFImageReader;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.net.Socket;
|
||||
import java.nio.file.Files;
|
||||
@@ -37,7 +31,7 @@ import java.util.TimeZone;
|
||||
|
||||
public class WebWorker implements Runnable {
|
||||
|
||||
private Socket socket;
|
||||
private final Socket socket;
|
||||
|
||||
/**
|
||||
* Constructor: must have a valid open socket
|
||||
@@ -54,6 +48,7 @@ public class WebWorker implements Runnable {
|
||||
public void run() {
|
||||
System.err.println("Handling connection...");
|
||||
try {
|
||||
System.out.println("Working Directory = " + System.getProperty("user.dir"));
|
||||
InputStream is = socket.getInputStream();
|
||||
OutputStream os = socket.getOutputStream();
|
||||
String file_path = readHTTPRequest(is);
|
||||
@@ -65,7 +60,6 @@ public class WebWorker implements Runnable {
|
||||
System.err.println("Output error: " + e);
|
||||
}
|
||||
System.err.println("Done handling connection.");
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,8 +82,6 @@ public class WebWorker implements Runnable {
|
||||
|
||||
// Check if it's a GET request.
|
||||
if (line_items[0].equals("GET")) {
|
||||
// System.out.println("found a get request");
|
||||
|
||||
// if it is lets get the file path its requesting to return it
|
||||
file_path = line_items[1];
|
||||
}
|
||||
@@ -102,7 +94,7 @@ public class WebWorker implements Runnable {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return "www" + file_path;
|
||||
return "./" + file_path;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,6 +166,13 @@ public class WebWorker implements Runnable {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to serve binary non-text files to the browser.
|
||||
*
|
||||
* @param os the output stream
|
||||
* @param file_path the path to the binary file
|
||||
* @throws IOException
|
||||
*/
|
||||
private void writeBinary(OutputStream os, String file_path) throws IOException {
|
||||
InputStream istream = new FileInputStream(file_path);
|
||||
int byteRead;
|
||||
@@ -182,6 +181,12 @@ public class WebWorker implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serves a text or html file to the browser.
|
||||
*
|
||||
* @param os the output stream
|
||||
* @param file_path the file path to the text file
|
||||
*/
|
||||
private void writeText(OutputStream os, String file_path) {
|
||||
|
||||
// Get the current date
|
||||
@@ -192,8 +197,7 @@ public class WebWorker implements Runnable {
|
||||
// render the file from the path
|
||||
BufferedReader reader;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(
|
||||
"./" + file_path));
|
||||
reader = new BufferedReader(new FileReader(file_path));
|
||||
String line = reader.readLine();
|
||||
while (line != null) {
|
||||
// read next line
|
||||
@@ -212,5 +216,4 @@ public class WebWorker implements Runnable {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
} // end class
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<project name="SimpleWebServer" default="cleanbuild" basedir="..">
|
||||
<description>
|
||||
Buildfile for the SimpleWebServer.
|
||||
</description>
|
||||
<property name="src" location="src/" />
|
||||
<property name="build" location="bin/" />
|
||||
|
||||
<target name="clean" description="delete class files">
|
||||
<delete dir="${build}"/>
|
||||
</target>
|
||||
|
||||
<target name="build" description="compiles java files to /bin">
|
||||
<mkdir dir="${build}"/>
|
||||
<javac srcdir="${src}" destdir="${build}"/>
|
||||
</target>
|
||||
|
||||
<target name="cleanbuild" depends="clean,build"/>
|
||||
|
||||
<target name="run" description="launches SimpleWebServer on port 8080">
|
||||
<java classname="edu.nmsu.cs.webserver.WebServer" classpath="${build}" fork="true" >
|
||||
<arg value="8080"/>
|
||||
</java>
|
||||
|
||||
</target>
|
||||
</project>
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 439 KiB After Width: | Height: | Size: 6.5 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 7.5 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 9.3 KiB |
@@ -1,7 +1,46 @@
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<p>Hello world, the current date is: <cs371date>. The server is: <cs371server>.</p>
|
||||
</body>
|
||||
</html>
|
||||
<head>
|
||||
<title>Welcome to my server</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Hello world, the current date is: <cs371date>. The server is: <cs371server>.</h1>
|
||||
|
||||
<hr>
|
||||
<p>Here are some GIFS</p>
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge">
|
||||
<img src="dogeDance.gif" alt="Dancing Doge"><br>
|
||||
|
||||
<p>This one is a PNG</p>
|
||||
<img src="cheemsBonk.png" alt="Dancing Doge">
|
||||
|
||||
<p>This one is a JPG</p>
|
||||
<img src="cheemsHello.jpg" alt="Dancing Doge">
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in new issue
Block a user