mice.java

来自「实现简单的远程监控」· Java 代码 · 共 70 行

JAVA
70
字号
package com.cheng;

import java.io.*;
import java.net.*;
import java.awt.*;
import javax.swing.*;
import java.awt.image.BufferedImage;

public class Mice implements Runnable {
    private ServerSocket server;
    private BufferedImage image;
    private DataInputStream in;
    private Thread t = null;
    private ImageIcon icon;
    private final int []PORT ={1978,2006,4000,8000};
    private static int portIndex=0;
    private static Mice mice;

    private Mice() {
       t=new Thread(this);
       t.start();
    }

    //返回唯一实例
    public static Mice getInstance() {
        return ((null == mice) ? mice=new Mice() : null);
    }

    public void run() {
        try {
            server = new ServerSocket(PORT[portIndex]);
            while (true) {
                Socket socket = server.accept();
                if (false == ThreadInfo.SendIsLive) {
                    new SendThread(socket).start();
                }
                if (false == ThreadInfo.CoopIsLive) {
                    new Coop(socket).start();
                }
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            try {
                portIndex++;
                if(portIndex>3)
                    portIndex=0;
                server.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }

    }

    /***
     * Main方法
     */
    public static void main(String args[]) {
        try
        {
            Mice m=Mice.getInstance();
        }
        catch(Exception ee)
        {
        }
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?