Skip to content

Instantly share code, notes, and snippets.

@mmpataki
Created July 8, 2022 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmpataki/6350ba97563b954bedbe2ec2b069ba26 to your computer and use it in GitHub Desktop.
Save mmpataki/6350ba97563b954bedbe2ec2b069ba26 to your computer and use it in GitHub Desktop.
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