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;
|
}
|
|
|
}
|