unable to start the monitor on 4454 ,an other instance is problaly using the same port

2023-05-16

 在打开idea studio后,再打开android studio,或者反过来,打开项目的时候就会报:unable to start the monitor on 4454 ,an other instance is problaly using the same port 这个错误。
 经过一番苦苦查找,原来是由于Log4JPlugin造成的,启用这个插件会打开本机的4454进行socket通讯。
 在log4Jplugin.jar中有一个LogServer类,代码如下:
package com.webspherious;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
import javax.net.ServerSocketFactory;

public class LogServer
{
  private static final int PORT_NUM = 4454;
  private static ServerSocket serverSocket;

  public static void main(String[] args)
  {
    serverSocket = createServerSocket();
    listenAndPrintLogMessages();
  }

  private static void listenAndPrintLogMessages()
  {
    for (;;)
    {
      Socket socket = null;
      try
      {
        System.out.println(" >> Server waiting for log messages...");
        socket = serverSocket.accept();

        InputStream is = socket.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        String line = null;
        while ((line = br.readLine()) != null) {
          System.out.println(line);
        }
        if (socket != null) {
          try
          {
            socket.close();
          }
          catch (IOException ignored) {}
        }
      }
      catch (Exception e) {}finally
      {
        if (socket != null) {
          try
          {
            socket.close();
          }
          catch (IOException ignored) {}
        }
      }
    }
  }

  private static ServerSocket createServerSocket()
  {
    ServerSocketFactory serverSocketFactory = ServerSocketFactory.getDefault();
    try
    {
      serverSocket = serverSocketFactory.createServerSocket(4454);
    }
    catch (IOException ioEx)
    {
      System.err.println("Unable to create server");
      ioEx.printStackTrace();
      System.exit(-1);
    }
    return serverSocket;
  }
}
由此有以下解决办法:
1、禁用该插件。
2、一个默认,另外一个改成其他未被占用的端口,修改端口后,要修改与之相关的配置文件中的端口配置信息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

unable to start the monitor on 4454 ,an other instance is problaly using the same port 的相关文章

随机推荐