I'm using this piece of code that exposes a simple function using a socket:
while (true) {
try {
ServerSocket serverSocket = new ServerSocket(7070);
Socket clientSocket = serverSocket.accept();
String input = (new BufferedReader(new InputStreamReader(clientSocket.getInputStream()))).readLine();
synchronized (this.map) {
ObjectOutputStream o = new ObjectOutputStream(clientSocket.getOutputStream());
o.writeChars(map.get(input));
o.close();
}
clientSocket.close();
serverSocket.close();
} catch(Exception e) {
e.printStackTrace();
}
}
What am I doing wrong? logging shows that it gets stuck in the input reception line and it sometimes throws an exception saying that the socket is in use