lpr-b:nameserver
no way to compare when less than two revisions
Differenze
Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.
| — | lpr-b:nameserver [13/11/2007 alle 18:53 (18 anni fa)] (versione attuale) – creata Marco Danelutto | ||
|---|---|---|---|
| Linea 1: | Linea 1: | ||
| + | <code java> | ||
| + | package nslookup; | ||
| + | import java.io.IOException; | ||
| + | import java.net.InetAddress; | ||
| + | import java.net.ServerSocket; | ||
| + | import java.net.Socket; | ||
| + | import java.util.Collections; | ||
| + | import java.util.HashMap; | ||
| + | import java.util.Map; | ||
| + | import java.util.concurrent.Executor; | ||
| + | import java.util.concurrent.ExecutorService; | ||
| + | import java.util.concurrent.Executors; | ||
| + | |||
| + | public class NameServer { | ||
| + | |||
| + | public static final int NAMESERVERPORT = 54321; | ||
| + | |||
| + | public static final int MAXTHREADS = 4; | ||
| + | |||
| + | /** | ||
| + | * @param args | ||
| + | */ | ||
| + | public static void main(String[] args) { | ||
| + | |||
| + | /** this is the cache, accessed through the host name ... */ | ||
| + | HashMap< | ||
| + | Map cache = Collections.synchronizedMap(uscache); | ||
| + | | ||
| + | /** this is the thread pool aimed at serving the requests ... */ | ||
| + | ExecutorService tp = Executors.newFixedThreadPool(MAXTHREADS); | ||
| + | |||
| + | /** prepare the server socket to accept request ... */ | ||
| + | ServerSocket ss = null; | ||
| + | try { ss = new ServerSocket(NAMESERVERPORT); | ||
| + | } | ||
| + | |||
| + | while (true) { /** main server loop */ | ||
| + | System.out.println(" | ||
| + | Socket s = null; | ||
| + | try { s = ss.accept(); | ||
| + | System.out.println(" | ||
| + | tp.execute(new ServerThread(cache, | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | </ | ||
lpr-b/nameserver.txt · Ultima modifica: 13/11/2007 alle 18:53 (18 anni fa) da Marco Danelutto
