in agent/src/main/java/com/attachme/agent/AttachmeServer.java [50:80]
private void runServer() throws IOException, ClassNotFoundException {
try (ServerSocket server = new ServerSocket(this.port)) {
server.setSoTimeout(500);
this.log.info("AttachMe listening for debuggee processes on port " + this.port);
while (!Thread.currentThread().isInterrupted()) {
try (Socket accept = server.accept()) {
try {
String clientAddress = accept.getRemoteSocketAddress().toString().split("/")[1].split(":")[0];
InputStream inputStream = accept.getInputStream();
ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
ProcessRegisterMsg msg = (ProcessRegisterMsg) objectInputStream.readObject();
listener.onDebuggeeProcess(msg, clientAddress);
this.log.info("Registered a debuggee process with pid " + msg.getPid() + " and possible ports " + msg.getPorts().toString());
} catch (RuntimeException e) {
e.printStackTrace();
this.log.error(exceptionToString(e));
}
} catch (IOException ignored) { // This includes SocketTimeoutException as well
}
}
this.log.info("Stopping attachme");
listener.onFinished();
} catch (BindException e) {
log.error("Could not bind to the port " + this.port + ". Maybe another process is using that port (possibly another IntelliJ IDEA).");
handleError(e);
} catch (Exception e) {
log.error("Unhandled error occurred, please report");
handleError(e);
throw e;
}
}