| | |
| | | import java.net.DatagramPacket; |
| | | import java.net.DatagramSocket; |
| | | import java.net.InetAddress; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.concurrent.ExecutorService; |
| | | import java.util.concurrent.Executors; |
| | | import java.util.concurrent.atomic.AtomicLong; |
| | | import dell_system.MessageViewPanel; |
| | | |
| | | public class UDPPortBReceiver { |
| | | public static final int PORT = 7000; |
| | | @SuppressWarnings("unused") |
| | | private static final int MAX_DEVICES = 50000; |
| | | private static final AtomicLong packetCount = new AtomicLong(0); |
| | | private static final ExecutorService executor = Executors.newFixedThreadPool(10); |
| | | private static DatagramSocket socket; |
| | | private static volatile boolean isRunning = false; |
| | | private static Thread receiverThread; |
| | | @SuppressWarnings("unused") |
| | | private static final int LOCAL_PORT = PORT; // 定义本地端口 |
| | | // 启动接收器的静态方法 |
| | | public static void startReceiver() { |
| | |
| | | String ip = packet.getAddress().getHostAddress(); |
| | | int port = packet.getPort(); |
| | | String hexData = bytesToHex(packet.getData(), packet.getLength()); |
| | | packetCount.incrementAndGet(); |
| | | // 获取当前时间和时间戳 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String time = sdf.format(new Date()); |
| | | int timestamp = (int)(System.currentTimeMillis() / 1000); |
| | | |
| | | // 保存到HexBaowen集合 |
| | | // 调用时添加本地端口参数 |
| | | HexBaowen.intsert(ip, hexData, time, port, LOCAL_PORT, timestamp); |
| | | PacketProcessingSystem.storePacket(ip, port, hexData); |
| | | |
| | | } catch (Exception e) { |
| | | System.err.println("Error processing UDP-A packet: " + e.getMessage()); |
| | |
| | | executor.shutdown(); |
| | | } |
| | | |
| | | // 发送数据到指定设备 |
| | | // 发送数据到指定设备 |
| | | public static void sendData(String ip, int port, String data, boolean isHex) { |
| | | try { |