Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package com.example;
import java.io.IOException;
import java.net.ServerSocket;
import java.util.Date;
import java.util.stream.LongStream;
public class TimeServer {
public static void main(String[] args) throws IOException {
ServerSocket listener = new ServerSocket(3001);
LongStream.iterate(0, i -> i)
.parallel()
.mapToObj(x -> {
try { return listener.accept(); }
catch (IOException e) { throw new RuntimeException(e); }
})
.forEach(sock -> {
try {
sock.getOutputStream().write(new Date().toString().getBytes());
sock.close();
}
catch (Exception e) { throw new RuntimeException(e); }
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment