远程端口关机的server

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) {

}

}

}


猜你喜欢

转载自l62s.iteye.com/blog/1568842
今日推荐