parent
667fa242d3
commit
f0707c5412
|
@ -14,7 +14,7 @@ import javax.swing.*;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException, InterruptedException {
|
public static void main(String[] args) {
|
||||||
log.info(" 当前系统类型: {}", SystemUtils.getOsName());
|
log.info(" 当前系统类型: {}", SystemUtils.getOsName());
|
||||||
try {
|
try {
|
||||||
//设置窗口主题
|
//设置窗口主题
|
||||||
|
|
|
@ -104,14 +104,21 @@ public class MainWindow extends JFrame {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initSocket() {
|
public static void initSocket() {
|
||||||
SocketFactory.start();
|
if(SocketFactory.start()){
|
||||||
|
setView("socket 服务启动成功");
|
||||||
|
}else{
|
||||||
|
setView("socket 服务启动失败,请检查8997端口是否被占用");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopSocket() {
|
public void stopSocket() {
|
||||||
try {
|
try {
|
||||||
SocketFactory.stop();
|
if(SocketFactory.stop()){
|
||||||
|
setView("服务停止成功");
|
||||||
|
}else{
|
||||||
|
setView("服务停止失败");
|
||||||
|
}
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
setView("服务关闭");
|
|
||||||
log.info("服务关闭");
|
log.info("服务关闭");
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
|
@ -28,35 +28,37 @@ public class SocketFactory {
|
||||||
* 获取Socket客户端
|
* 获取Socket客户端
|
||||||
* @return socketServer
|
* @return socketServer
|
||||||
*/
|
*/
|
||||||
private static SocketServer getSocket(){
|
private static SocketServer getSocket() throws UnknownHostException {
|
||||||
try {
|
log.info("Create Socket ...");
|
||||||
log.info("Create Socket ...");
|
socketServer = new SocketServer(8997);
|
||||||
socketServer = new SocketServer(8997);
|
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
return socketServer;
|
return socketServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动socket服务
|
* 启动socket服务
|
||||||
*/
|
*/
|
||||||
public static void start(){
|
public static boolean start() {
|
||||||
getSocket().start();
|
try {
|
||||||
|
getSocket().start();
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
log.info("socket 已启动");
|
log.info("socket 已启动");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 停止socket服务
|
* 停止socket服务
|
||||||
*/
|
*/
|
||||||
public static void stop(){
|
public static boolean stop(){
|
||||||
try {
|
try {
|
||||||
if(socketServer != null){
|
if(socketServer != null){
|
||||||
socketServer.stop();
|
socketServer.stop();
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new RuntimeException(e);
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue