添加端口被占用时的提示说明
This commit is contained in:
@@ -80,9 +80,12 @@ public class LoFileServer {
|
|||||||
|
|
||||||
channel = b.bind(port).sync().channel();
|
channel = b.bind(port).sync().channel();
|
||||||
Logger.info("***** Welcome To LoServer on port [{}], startting spend {}ms *****", port, DateUtil.spendMs(start));
|
Logger.info("***** Welcome To LoServer on port [{}], startting spend {}ms *****", port, DateUtil.spendMs(start));
|
||||||
} finally {
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
Logger.error("端口 {} 已经被占用。请检查该端口被那个程序占用,找到程序停掉。\n查找端口被那个程序占用的命令是: netstat -tunlp | grep {}", port, port);
|
||||||
|
System.out.println("端口 " + port + " 已经被占用。请检查该端口被那个程序占用,找到程序停掉。\n查找端口被那个程序占用的命令是: netstat -tunlp | grep " + port);
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
if (this.channel != null) {
|
if (this.channel != null) {
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ public class LoServer {
|
|||||||
|
|
||||||
registerAllAction();
|
registerAllAction();
|
||||||
|
|
||||||
|
int bindingPort = port;
|
||||||
try {
|
try {
|
||||||
final ServerBootstrap b = new ServerBootstrap();
|
final ServerBootstrap b = new ServerBootstrap();
|
||||||
final ServerBootstrap adminB = new ServerBootstrap();
|
final ServerBootstrap adminB = new ServerBootstrap();
|
||||||
@@ -87,6 +88,7 @@ public class LoServer {
|
|||||||
channel = b.bind(port).sync().channel();
|
channel = b.bind(port).sync().channel();
|
||||||
|
|
||||||
|
|
||||||
|
bindingPort = adminPort;
|
||||||
adminB.group(bossGroup, workerGroup)
|
adminB.group(bossGroup, workerGroup)
|
||||||
.channel(NioServerSocketChannel.class)
|
.channel(NioServerSocketChannel.class)
|
||||||
.option(ChannelOption.SO_BACKLOG, 10240) // 服务端可连接队列大小
|
.option(ChannelOption.SO_BACKLOG, 10240) // 服务端可连接队列大小
|
||||||
@@ -108,10 +110,14 @@ public class LoServer {
|
|||||||
|
|
||||||
adminChannel = adminB.bind(adminPort).sync().channel();
|
adminChannel = adminB.bind(adminPort).sync().channel();
|
||||||
Logger.info("***** Welcome To LoServer on port [{},{}], startting spend {}ms *****", port, adminPort, DateUtil.spendMs(start));
|
Logger.info("***** Welcome To LoServer on port [{},{}], startting spend {}ms *****", port, adminPort, DateUtil.spendMs(start));
|
||||||
} finally {
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
Logger.error("端口 {} 已经被占用。请检查该端口被那个程序占用,找到程序停掉。\n查找端口被那个程序占用的命令是: netstat -tunlp | grep {}", bindingPort, bindingPort);
|
||||||
|
System.out.println("端口 " + bindingPort + " 已经被占用。请检查该端口被那个程序占用,找到程序停掉。\n查找端口被那个程序占用的命令是: netstat -tunlp | grep " + bindingPort);
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
if (this.channel!= null) {
|
if (this.channel!= null) {
|
||||||
this.channel.close();
|
this.channel.close();
|
||||||
|
|||||||
@@ -149,12 +149,10 @@ public class NettyAcceptor implements ServerAcceptor {
|
|||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
LOG.error("An interruptedException was caught while initializing server. Protocol={}", protocol, ex);
|
LOG.error("An interruptedException was caught while initializing server. Protocol={}", protocol, ex);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if(e instanceof BindException) {
|
e.printStackTrace();
|
||||||
e.printStackTrace();
|
LOG.error("端口 {} 已经被占用。请检查该端口被那个程序占用,找到程序停掉。\n查找端口被那个程序占用的命令是: netstat -tunlp | grep {}", port, port);
|
||||||
LOG.error("端口 {} 已经被占用。请检查该端口被那个程序占用,找到程序停掉。\n查找端口被那个程序占用的命令是: netstat -tunlp | grep {}", port, port);
|
System.out.println("端口 " + port + " 已经被占用。请检查该端口被那个程序占用,找到程序停掉。\n查找端口被那个程序占用的命令是: netstat -tunlp | grep " + port);
|
||||||
System.out.println("端口 " + port + " 已经被占用。请检查该端口被那个程序占用,找到程序停掉。\n查找端口被那个程序占用的命令是: netstat -tunlp | grep " + port);
|
System.exit(-1);
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user