Created
August 13, 2017 16:44
-
-
Save dayvsonlima/c7f9e923daa0412b7215d1bc1a225af3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.net.*; | |
import java.io.*; | |
import java.io.IOException; | |
import java.util.Scanner; | |
public class Server { | |
public static void main(String args[]) throws IOException { | |
ServerSocket server = new ServerSocket(2345); | |
System.out.println("Start server"); | |
while(true) { | |
Socket client = server.accept(); | |
Scanner scanner = new Scanner(client.getInputStream()); | |
System.out.println(scanner.nextLine()); | |
PrintWriter out = new PrintWriter(client.getOutputStream(), true); | |
String content = new String("Coeh rapaziada"); | |
out.println( | |
"HTTP/1.1 200 OK\r\n" + | |
"Content-Type: text/plain\r\n" + | |
"Content-Length: " + content.length() + "\r\n" + | |
"Connection: close\r\n" + | |
"\r\n" + | |
content); | |
client.close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment