Created
July 8, 2022 09:27
-
-
Save mmpataki/6350ba97563b954bedbe2ec2b069ba26 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
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