Skip to content

Instantly share code, notes, and snippets.

@dayvsonlima
Created August 13, 2017 16:44
Show Gist options
  • Save dayvsonlima/c7f9e923daa0412b7215d1bc1a225af3 to your computer and use it in GitHub Desktop.
Save dayvsonlima/c7f9e923daa0412b7215d1bc1a225af3 to your computer and use it in GitHub Desktop.
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