package TeamSeven.server;

import TeamSeven.server.socket.ServerSocket;
import TeamSeven.server.socket.ServerSocketImpl;
import org.java_websocket.WebSocketImpl;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by joshoy on 16/3/22.
 */
public class Server {
    /*
    * 服务端主函数
    * */
    public static void main(String[] args) throws InterruptedException , IOException {
        WebSocketImpl.DEBUG = true;
        int port = 8887;

        try {
            /* 自定义端口 */
            port = Integer.parseInt(args[0]);
        } catch ( Exception ex ) {
        }

        ServerSocket s = new ServerSocketImpl(port);
        s.start();

        /* 启动Server后 */
        System.out.println("[*] 服务器已启动, 端口" + port + ", 输入restart重启, 输入exit退出. 其他广播消息可直接输入.");
        BufferedReader sysin = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String in = sysin.readLine();
            if (in.equals("exit")) {
                s.stop();
                System.out.println("[*] 服务器已退出.");
                break;
            } else if (in.equals("restart")) {
                s.stop();
                s = new ServerSocketImpl(port);
                s.start();
                System.out.println("[*] 服务器已重启, 输入restart重启, 输入exit退出. 其他广播消息可直接输入.");
            }
            else {
                System.out.println("[*] [系统广播] " + in);
                s.sendToAll("[系统广播] " + in);
            }
        }
    }



}

@@ -175,84 +175,149 @@
 .io.
-BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader
+*;%0A%0Aimport java.text.DateFormat;%0Aimport java.text.SimpleDateFormat;%0Aimport java.util.Date;%0Aimport java.util.Timer;%0Aimport java.util.TimerTask
 ;%0A%0A/
@@ -731,32 +731,32 @@
 cketImpl(port);%0A
-
         s.start(
@@ -759,16 +759,928 @@
 art();%0A%0A
+        /* %E5%BC%80%E5%A7%8B%E5%AE%9A%E6%97%B6%E8%AE%B0%E5%BD%95 */%0A        TimerTask task = new TimerTask() %7B%0A%0A            @Override%0A            public void run() %7B%0A%0A                Date dt = new Date();%0A                DateFormat df = new SimpleDateFormat( %22yyyy/MM/dd HH:mm:ss%22 );%0A                String time = df.format( dt );%0A%0A                try %7B%0A%0A                    String fileName = %22./log/server.txt%22;%0A                    FileWriter writer = new FileWriter( fileName, true );%0A                    System.out.println( time + %22  %E6%8E%A5%E6%94%B6%E6%B6%88%E6%81%AF%E6%95%B0%E9%87%8F:   %E5%BF%BD%E7%95%A5%E6%B6%88%E6%81%AF%E6%95%B0%E9%87%8F:  %22 );  //received/ignored messages number%0A                    writer.write( time + %22  %E6%8E%A5%E6%94%B6%E6%B6%88%E6%81%AF%E6%95%B0%E9%87%8F:   %E5%BF%BD%E7%95%A5%E6%B6%88%E6%81%AF%E6%95%B0%E9%87%8F:  %5Cn%22 );%0A                    writer.close();%0A%0A                %7D catch (IOException e) %7B%0A                    e.printStackTrace();%0A                    System.out.println( %22error%22 );%0A                %7D%0A            %7D%0A        %7D;%0A%0A        Timer timer = new Timer();%0A        timer.schedule(task, 0, 60000);%0A%0A%0A
         

set timer task