zsh_root
2024-01-02 7b595546af704983dbafcd0d385c8768ddacefc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package udp_out;
 
 
import Method.BaoWenShow;
import Method.SaveFIleInTxt;
import PbuliClass.ShowMessage;
import PbuliClass.Systems;
import home.Open_soft_dialog;
 
import java.io.IOException;
import java.net.*;
import java.util.Vector;
 
/**
 * 2023.07.12 zsh
 */
public class udpAndTcpout implements Runnable {
    static int k = 0;
    static int sleeptime = 1;
    //ת·¢Êý¾Ý
    static Vector<udppojo> udppojoVector = new Vector<>();
    static boolean savebaowen = Systems.sys().getOpensave().equals("1");
    static DatagramSocket socket = null;
    static DatagramPacket packet = null;
 
    static {
        try {
            socket = new DatagramSocket();
 
        } catch (SocketException e) {
            e.printStackTrace();
        }
    }
 
    /**
     * Æô¶¯Ï̵߳ķ½·¨
     */
    public void startThread() {
        Thread t = new Thread(this);
        t.start();
        Open_soft_dialog.addara("Æô¶¯Êý¾Ýת·¢Ïß³Ì...");//×Ô¶¯Ôö¼ÓÀúÊ·¹ì¼£±í
    }
 
 
    public void run() {
        while (true) {
            try {
                outDisData();
                Thread.sleep(sleeptime);//ÐÝÃßʱ¼ä
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
 
        }
    }
 
 
    public static void outDisData() {
        if (udppojoVector.size() > 10000) {
            udppojoVector.removeAllElements();
        } else {
            if (udppojoVector.size() == 0) {
                sleeptime = 100;
            } else {
                sleeptime = 1;
                udpout();
 
            }
        }
    }
 
 
    public static void udpout() {
        int size = udppojoVector.size();
        if (size == 0) {
            return;
        }
 
        udppojo udppojo = udppojoVector.get(0);
        byte[] data = udppojo.getData();
        int length = udppojo.getLength();
        InetAddress ip = udppojo.getIp();
        int port = udppojo.getPort();
        String message = udppojo.getMessage();
        String tagid = udppojo.getTagid();
        try {
            packet = new DatagramPacket(data, length, ip, port);
        } catch (Exception e) {
            e.printStackTrace();
        }
 
        try {
            socket.send(packet);
            if (!message.equals("0000") && !tagid.equals("0000")) {
                BaoWenShow.show(message, "UDPת·¢", tagid);
                if (savebaowen) {
                    SaveFIleInTxt.save_display(message, tagid);
                }
            }
        } catch (IOException e) {
            if (k == 0) {
                ShowMessage.zidingyi(ip + ":" + port + "·¢ËÍʧ°Ü...");
                k++;
            }
        }
        udppojoVector.remove(udppojo);
 
}
 
 
    public static Vector<udppojo> getUdppojoVector() {
        return udppojoVector;
    }
 
 
}