Last active
December 26, 2019 17:26
-
-
Save SantriptaSharma/24558005175e40b850e52ddb4f5ea377 to your computer and use it in GitHub Desktop.
GCI Task- Create a simple HTTP server using java
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
/* | |
Build Instructions: | |
$ javac HTTPServer.java | |
$ java HTTPServer | |
*/ | |
import java.net.ServerSocket; | |
import java.net.Socket; | |
import java.io.IOException; | |
public class HTTPServer | |
{ | |
public static void main(String[] args) throws IOException | |
{ | |
int port = 7250; | |
ServerSocket server = new ServerSocket(port); | |
System.out.println("Server Started on " + port); | |
while(true) | |
{ | |
try(Socket client = server.accept()) | |
{ | |
String response = "HTTP/1.1 200 OK\r\n\r\n" + "GCI Task"; | |
client.getOutputStream().write(response.getBytes("UTF-8")); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment