rava2
home
documentation
examples
public class Main { public static void main(String[] args) { System.out.println("Starting socket loop test on 8093"); ServerSocket server = new ServerSocket(8093); int count = 0; while (true) { Socket client = server.accept(); var input = client.getInputStream(); var output = client.getOutputStream(); String req = input.readLine(); while (true) { String line = input.readLine(); if (line == null || line.length() == 0) break; } String body = "Request " + count; String resp = "HTTP/1.1 200 OK\r\nContent-Length: " + body.length() + "\r\nConnection: close\r\n\r\n" + body; output.write(resp); client.close(); count++; if (count % 10 == 0) { System.out.println("Handled " + count + " requests"); } } } }
run program
ready