Answered step by step
Verified Expert Solution
Link Copied!

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 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 "
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions