JLChen
2021-12-10 04122050f9b2bf5612d26f8394cc2ead03b57258
HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/client/UdpClient.java
@@ -19,6 +19,7 @@
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -38,7 +39,7 @@
    private final byte[] receiveByte;
    private final String ip;
//    private final String ip;
    private final int port;
@@ -54,16 +55,10 @@
     */
    private UdpClient(String ip, int port, int monitorPort, int sendPort, SocketOptions socketOptions) {
        this.socketOptions = socketOptions;
        this.ip = ip;
        this.socketOptions.setIp(ip);
        this.port = port;
        this.sendPort = sendPort;
        this.monitorPort = monitorPort;
        this.receiveByte = new byte[BUFFER];
    }
    public UdpClient(String ip, int port) {
        this.ip = ip;
        this.port = port;
        this.receiveByte = new byte[BUFFER];
    }
@@ -135,10 +130,8 @@
        }
        //排除自己发出去的
        try {
            if (receivePacket.getAddress().getHostAddress()
                    .equals(IpUtils.getIP(HDLSdk.getInstance().getContext()))) {
            if (IpUtils.isLocalIpAddress( receivePacket.getAddress().getHostAddress()))
                return;
            }
        } catch (Exception ignored) {
        }
@@ -164,7 +157,8 @@
        if (msg == null) {
            msg = new byte[1];
        }
        InetAddress serverAddress = InetAddress.getByName(ip);
        InetAddress serverAddress = InetAddress.getByName(getOptions().getIp());
        LogUtils.e("发送目标IP地址:"+getOptions().getIp());
        final DatagramPacket sendPacket = new DatagramPacket(msg, msg.length, serverAddress, port);
        if (sendPort < 0) {
            final DatagramSocket sendSocket = new DatagramSocket();