forked from BruceEckel/OnJava8-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiServer.java
More file actions
29 lines (28 loc) · 810 Bytes
/
Copy pathMultiServer.java
File metadata and controls
29 lines (28 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// network/MultiServer.java
// (c)2017 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Uses concurrency to handle any number of clients.
import java.io.*;
import java.net.*;
import java.util.concurrent.*;
public class MultiServer implements Runnable {
private final int port;
public MultiServer(int port) {
this.port = port;
}
@Override
public void run() {
System.out.println("Server: Running");
try (
ServerSocket ss = new ServerSocket(port)
) {
System.out.println("Server: " + ss);
for(int i = 0; i < 10; i++)
CompletableFuture
.runAsync(new SimpleServer(ss));
} catch(IOException e) {
throw new RuntimeException(e);
}
}
}