Друзья, помогите разобраться что не так.
package com.javarush.task.task30.task3008;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class Server {
private static Map<String, Connection> connectionMap = new ConcurrentHashMap<>();
public static void sendBroadcastMessage(Message message){
for (String key: connectionMap.keySet()) {
try {
connectionMap.get(key).send(message);
} catch (IOException e) {
e.printStackTrace();
System.out.println("Сообщение не было отправленно!");
}
}
}
public static void main(String[] args) throws IOException {
ServerSocket serverSocket= new ServerSocket(ConsoleHelper.readInt());
System.out.println("Сервер запущен");
try {
while (true) {
Socket socket = serverSocket.accept();
Handler handler = new Handler(socket);
handler.start();
}
}catch (IOException e){
System.out.println("Произошла ошибка");
serverSocket.close();
}
}
private static class Handler extends Thread{
Socket socket;
public Handler(Socket socket) {
this.socket = socket;
}
private String serverHandshake(Connection connection) throws IOException, ClassNotFoundException {
Message message = new Message(MessageType.NAME_REQUEST, "Введите имя");
connection.send(message);
// Message answer=null;
String name=null;
while (true) {
// connection.send(message);
// answer=connection.receive();
if (connection.receive().getType()!= MessageType.USER_NAME) connection.send(message);
else if (connection.receive().getData()==null) connection.send(message);
else if (connectionMap.containsKey(connection.receive().getData()))connection.send(message);
else {
connectionMap.put(connection.receive().getData(),connection);
connection.send(new Message(MessageType.USER_ADDED,"Имя было принято"));
name = connection.receive().getData();
break;
}
}
return name;
}
}
}