Created
March 5, 2014 09:02
-
-
Save bjorn-ali-goransson/9363694 to your computer and use it in GitHub Desktop.
Webserver version 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.DataOutputStream; | |
import java.net.ServerSocket; | |
import java.util.Date; | |
public class WebServerTest { | |
public static void main(String[] args) throws Exception{ | |
String newLine = "\n"; | |
System.out.println("Starting server..."); | |
ServerSocket server = new ServerSocket(8199); | |
while(true){ | |
System.out.println("Waiting for requests..." + newLine + newLine); | |
DataOutputStream out = new DataOutputStream(server.accept().getOutputStream()); | |
String responseString = "HTTP/1.1 200 OK" + newLine | |
+ "Content-Type: text/html" + newLine | |
+ newLine | |
+ "Hello,<br> world! " + new Date().toString(); | |
System.out.print(responseString); | |
out.writeBytes(responseString); | |
out.close(); | |
} | |
// System.out.println("Press any key to exit..."); | |
// System.in.read(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment