@@ -0,0 +1,3317 @@
+package tttserver;%0A%0Aimport java.io.IOException;%0Aimport java.net.ServerSocket;%0Aimport java.net.Socket;%0Aimport java.util.ArrayList;%0Aimport java.util.Scanner;%0Aimport java.io.PrintWriter;%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;%0A%0Apublic class TTTServer %7B%0A%0A    /**%0A     * @param args the command line arguments%0A     */%0A    public static void main(String%5B%5D args) throws IOException %7B%0A        %0A        final int PORT = 8888;%0A        ServerSocket server = null;%0A        Socket client = null;%0A        ArrayList%3CTTTServerThread%3E threads = null;%0A        Scanner in = null;%0A        PrintWriter out = null;%0A        %0A        ExecutorService pool = Executors.newCachedThreadPool();%0A        try %7B%0A            server = new ServerSocket(PORT);%0A            threads = new ArrayList%3CTTTServerThread%3E();%0A            %0A            outer_loop:%0A            while (true) %7B%0A                client = server.accept();%0A                in = new Scanner(client.getInputStream());%0A                out = new PrintWriter(client.getOutputStream());%0A                %0A                String str = in.nextLine();%0A                %0A                if (str.equals(%22HOST%22)) %7B%0A                    // Create new thread, host waits for a party to join%0A                    TTTServerThread newT = new TTTServerThread(client);%0A                    threads.add(newT);%0A                    pool.execute(newT);%0A                    System.out.println(%22New host added.%22);%0A                %7D%0A                else if (str.equals(%22JOIN%22)) %7B%0A                    String destIP = in.nextLine();%0A                    %0A                    System.out.println(%22Request from a party to join.%22);%0A                    %0A                    // Check the list with active hosts%0A                    for (int i = 0; i %3C threads.size(); i++) %7B%0A                        TTTServerThread hostT = threads.get(i);%0A                        String hostIP = hostT.getIPAddress();%0A                        %0A                        // Check if the host is still active%0A                        if (!hostT.isActive()) %7B%0A                            threads.remove(i);%0A                            --i;%0A                            continue;%0A                        %7D%0A                        %0A                        // If the host and destination IPs match and connect the threads if they do%0A                        if (hostIP.equals(destIP)) %7B%0A                            TTTServerThread newT = new TTTServerThread(client);%0A                            %0A                            hostT.connect(newT);%0A                            newT.connect(hostT);%0A                            %0A                            pool.execute(newT);%0A                            threads.remove(i);%0A                            %0A                            hostT.begin();%0A                            newT.begin();%0A                            %0A                            continue outer_loop;%0A                        %7D%0A                    %7D%0A                    // The requested server is not found%0A                    out.println(%22254%22);%0A                    out.flush();%0A                %7D%0A            %7D%0A        %7D%0A        catch (IOException e) %7B%0A            System.err.println(e.getMessage());%0A        %7D%0A        finally %7B%0A            server.close();%0A            pool.shutdown();%0A        %7D%0A    %7D%0A%7D%0A

Create TTTServer.java