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