1
826220679@qq.com
2023-07-22 734291355c39914629aafb6ae1b0b925b0e88538
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
package baowen;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;
import data_model.Dell_system;
import frame.Index1;
import publicclass.Open_soft_dialog;
import publicclass.ShowMessage;
 
/**¸ÃÀàÓÃÓÚ½ÓÊÕUDP±¨ÎÄ*/
 
public class Udp_Receive  implements Runnable {
 
    static DatagramSocket socket;
    int port=Dell_system.getPort();    
    DatagramPacket packet;
    byte[] byt=null;
    boolean G4=false;
    static int bytlenth=1024*3;
 
    int i=1;
    /**³õʼ»¯¶ÔÏó
     * @throws NumberFormatException 
     * @throws IOException */
    public  Udp_Receive() {
 
        try {
            socket = new DatagramSocket(port);
        } catch (SocketException e) {
            ShowMessage.zidingyi_24("°ó¶¨¶Ë¿Ú"+port+"ʧ°Ü");
        }        
        byte[] data = new byte[bytlenth]; // ´´½¨byteÊý×é
        packet= new DatagramPacket(data,bytlenth);
 
    }
 
 
    /**Æô¶¯Ï̵߳ķ½·¨*/
    public void startThread() {        
        Thread t=new Thread(this);
        t.start();
        Open_soft_dialog.addara("Æô¶¯"+port+"¶Ë¿Ú¼àÌý");
    }
 
 
    public void run() {
        while(true) {
            getdata();
        }
    }
 
    /**»ñÈ¡Êý¾Ý*/
    public  void getdata() {
        if(socket !=null) {
            try {                
                socket.receive(packet); // ½ÓÊÕÊý¾Ý°ü
                //Èç¹ûÔÝͣûÓÐÆô¶¯
                int lenth=packet.getLength();
                byt=subBytes(packet.getData(),0, lenth);
                //»ñÈ¡·¢ËͶ˵ÄIPµØÖ·¶ÔÏó
                String ip=packet.getAddress().getHostAddress();
                int port=packet.getPort();    
                String datas=Tools.Bytes2HexString(byt);
                String upinfo=datas.toUpperCase();    
                if(Index1.isShoware() && Index1.getTagid().equals("HEX")) {
                    Index1.ara_show(upinfo);
                }
                i=i+1;
                Index1.getUdpnum().setText(i+"Ìõ");    
                if(i==100000) {
                    i=0;
                }
                String message=new String(packet.getData(), 0, lenth);
                message=message.replaceAll(" ", "");
                message=message.replaceAll("\r\n", "");
                String infor2=message.toUpperCase();                
                Dell_baotou.dell_baotou_start(infor2,ip,port);
                Dell_55AA02.dell_55aa02_start(upinfo, ip, port);
                Dell_AACC.dell_AACC(upinfo, ip, port);
                if(Index1.isShoware() && Index1.getTagid().equals("ASCLL")) {
                    Index1.ara_show(infor2);
                }
                byt=null;
            } catch (Exception e) {
                e.printStackTrace(); // Êä³öÒì³£ÐÅÏ¢
            }
        }
    }
 
 
    public static DatagramSocket getSocket() {
        return socket;
    }
 
    public static byte[] subBytes(byte[] src, int begin, int count) {
        byte[] bs = new byte[count];
        System.arraycopy(src, begin, bs, 0, count);
        return bs;
    }
 
 
}