Question: import java.io . * ; import java.net. * ; import java.util. * ; public class MiddleServer { private static Map users = new HashMap >

import java.io.*;
import java.net.*;
import java.util.*;
public class MiddleServer {
private static Map users = new HashMap>();
public static void main(String[] args) throws IOException {
int port = Integer.parseInt(args[0]);
loadUsers();
ServerSocket serverSocket = new ServerSocket(port);
while (true){
new ClientHandler(serverSocket.accept()).start();
}
}
private static void loadUsers() throws IOException {
// Load users from userList.txt
}
private static class ClientHandler extends Thread {
private Socket socket;
public ClientHandler(Socket socket){
this.socket = socket;
}
public void run(){
try (BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter output = new PrintWriter(socket.getOutputStream(), true)){
String credentials = input.readLine();
String[] parts = credentials.split("");
String username = parts[0];
String password = parts[1];
if (authenticate(username, password)){
output.println("SUCCESS");
// Connect to appropriate group server
} else {
output.println("FAIL");
}
} catch (IOException e){
e.printStackTrace();
}
}
private boolean authenticate(String username, String password){
User user = users.get(username);
return user != null && user.password.equals(password);
}
}
private static class User {
String username;
String password;
String group;
int points;
// Constructor and other methods
}
}
" I need " Send me the instructions to execute and Outputs of this program "
 import java.io.*; import java.net.*; import java.util.*; public class MiddleServer { private

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!