Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 mainString args throws IOException
int port Integer.parseIntargs;
loadUsers;
ServerSocket serverSocket new ServerSocketport;
while true
new ClientHandlerserverSocketacceptstart;
private static void loadUsers throws IOException
Load users from userList.txt
private static class ClientHandler extends Thread
private Socket socket;
public ClientHandlerSocket socket
this.socket socket;
public void run
try BufferedReader input new BufferedReadernew InputStreamReadersocketgetInputStream;
PrintWriter output new PrintWritersocketgetOutputStream true
String credentials input.readLine;
String parts credentials.split;
String username parts;
String password parts;
if authenticateusername password
output.printlnSUCCESS;
Connect to appropriate group server
else
output.printlnFAIL;
catch IOException e
eprintStackTrace;
private boolean authenticateString username, String password
User user users.getusername;
return user null && user.password.equalspassword;
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started