package test.map;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JOptionPane;
public class ShutDownServer {
public void listen() {
ServerSocket socket;
try {
socket = new ServerSocket(18080);
while (true) {
Socket s = socket.accept();
while (!s.isConnected()) {
}
Processor.shutdown();
}
} catch (IOException e1) {
e1.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]) throws Exception {
new ShutDownServer().listen();
}
}
class Processor extends Thread {
Socket s = null;
public static void shutdown(){
Runtime run = Runtime.getRuntime();
try {
run.exec("cmd /k shutdown -s -t 30");
} catch (IOException e) {
e.printStackTrace();
}
}
public Processor(Socket s) throws Exception {
this.s = s;
}
public void run() {
try {
JOptionPane.showMessageDialog(null, "准备关机");
shutdown();
} catch (Exception e) {
}
}
}
本文介绍了一个使用Java编写的关机服务器的自动化脚本,通过创建ServerSocket监听特定端口并接受连接,实现远程关机功能。脚本中包含主函数启动监听过程和处理器类实现关机操作。
3436

被折叠的 条评论
为什么被折叠?



