Server (40 points): The server will contain the main(String[] args) method and will instantiate an instance of the Word Searcher object defined above. After that it will open a Server Socket and bind it to an available port. For my own system the port 1236 was open, but this may be different on your home computer. The server will sit in a while loop performing the following steps: 1. Accept client socket connection 2. Set up input/output streams from client connection 3. Read in String from client 4. Pass String to WordSearcher object, receive List output 5. Transmit Listsinteger> to client 6. Close Connection 7. Return to top of while loop Recommended communication format is detailed below. If you want to include a special "shutdown" command that causes the server to exit its while loop that is fine. You may also have while(1) to make a loop that runs forever and must be shut down manually in Eclipse.

Respuesta :

Here is a sample of how the server would be implemented

import java.io.*;

import java.net.*;

import java.util.*;

public class Server {

   public static void main(String[] args) {

       WordSearcher searcher = new WordSearcher();

       try {

           // Bind server socket to a port

           ServerSocket serverSocket = new ServerSocket(1236);

           System.out.println("Server socket created, waiting for clients...");

           while (true) {

               // Accept client connection

               Socket clientSocket = serverSocket.accept();

               System.out.println("Client connected: " + clientSocket.getInetAddress());

               // Set up input and output streams

               BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));

               PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);

               // Read in string from client

               String inputString = in.readLine();

               // Pass string to WordSearcher object and receive list output

               List<Integer> positions = searcher.search(inputString);

               // Transmit list to client

               for (Integer position : positions) {

                   out.println(position);

               }

               // Close connection

               clientSocket.close();

           }

       } catch (IOException e) {

           e.printStackTrace();

       }

   }

}

The implementation binds a server socket on port 1236 and listens for client connections. When a client connects, it sets up an input stream and an output stream for communicating with the client. It then reads a string from the client, passes it to a Word Searcher object to search for words, and sends a list of resulting positions to the client. Finally the connection is closed and it loops back to wait for the next client connection.

To include a special "shutdown" command, loop checking for that command, then break out of the loop and close the server socket when the command is received. One can also use a flag variable that is set to true when the shutdown command is received, and use that flag to break out of the loop.

Read more about loops on brainly.com/question/29586204

#SPJ4