求助,请你喝一杯☕️,帮忙把 Java 的代码翻译成 iOS 版。

33次阅读

共计 1025 个字符,预计需要花费 3 分钟才能阅读完成。

有安卓的同学会 iOS 的吗
求帮忙把下面的代码翻译成 iOS 的版本

iOS 项目用的第三方 socket 库 GCDAsyncSocket

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class teststr {
public static void main(String[] args) {
wakeup();
}
public static void wakeup(){
String mac = “00:30:64:69:F8:A7”; //mac 地址
// String mac = “00:02:a0:01:26:84”;
try {

        int port = 9;
        byte[] macByte = new byte[6];
        String[] ips = mac.split("\:|\-");
        for (int i = 0; i < 6; i++) {macByte[i] = (byte) Integer.parseInt(ips[i], 16);
        }
        // 用来存储网络唤醒数据包
        byte[] bys = new byte[6 + 16 * macByte.length];
        for (int i = 0; i < 6; i++) {bys[i] = (byte) 0xff;
        }
        for (int i = 6; i < bys.length; i += macByte.length) {System.arraycopy(macByte, 0, bys, i, macByte.length);
        }
        // 将字符形式的 IP 地址转换成标准的 IP 地址
        InetAddress address = InetAddress.getByName("192.168.100.255");

// InetAddress address = InetAddress.getByName("255.255.255.255");
// 生成标准的数据报
DatagramPacket pack = new DatagramPacket(bys, bys.length, address, port);
// 创建标准套接字,用来发送数据报
DatagramSocket socket = new DatagramSocket();
// 发送魔法包
socket.send(pack);
socket.close();
} catch (Exception e) {
e.printStackTrace();
} catch (Throwable e) {
e.printStackTrace();
}
}
}

正文完
 0