Skip to content

Instantly share code, notes, and snippets.

@bjorn-ali-goransson
Created March 5, 2014 09:02
Show Gist options
  • Save bjorn-ali-goransson/9363694 to your computer and use it in GitHub Desktop.
Save bjorn-ali-goransson/9363694 to your computer and use it in GitHub Desktop.
Webserver version 2
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