Skip to content

Instantly share code, notes, and snippets.

@stefanhaustein
Last active June 24, 2018 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanhaustein/d0691defbcbf1af8449c6352ae39c39e to your computer and use it in GitHub Desktop.
Save stefanhaustein/d0691defbcbf1af8449c6352ae39c39e to your computer and use it in GitHub Desktop.
import java.io.*;
import java.net.*;
public class Httpd {
public static void main(String[] args) throws IOException {
ServerSocket v = new ServerSocket(8080);
for (;;) {
Socket s = v.accept();
try {
InputStream i = new FileInputStream(new BufferedReader(new InputStreamReader(s.getInputStream())).readLine().split(" ")[1]);
new PrintStream(s.getOutputStream()).println("HTTP/1.0 200 OK\n");
for(int b; (b = i.read()) != -1;) s.getOutputStream().write(b);
s.close();
} catch (IOException e) {}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment