English just isn’t my native language; please excuse typing errors.
Now have Java code
How can I obtain the identical operate on iOS (iOS initiatives use GCDAsyncSocket to implement socket communication)
import java.internet.DatagramPacket;
import java.internet.DatagramSocket;
import java.internet.InetAddress;
public class teststr {
public static void predominant(String[] args) {
wakeup();
}
public static void wakeup(){
String mac = "00:30:64:6b:5f:9c"; //mac地址
attempt {
int port = 9;
byte[] macByte = new byte[6];
String[] ips = mac.break up(":|-");
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.size; i += macByte.size) {
System.arraycopy(macByte, 0, bys, i, macByte.size);
}
// 将字符形式的IP地址转换成标准的IP地址
InetAddress handle = InetAddress.getByName("192.168.100.255");
// InetAddress handle = InetAddress.getByName("255.255.255.255");
// 生成标准的数据报
DatagramPacket pack = new DatagramPacket(bys, bys.size, handle, port);
// 创建标准套接字,用来发送数据报
DatagramSocket socket = new DatagramSocket();
// 发送魔法包
socket.ship(pack);
socket.shut();
} catch (Exception e) {
e.printStackTrace();
} catch (Throwable e) {
e.printStackTrace();
}
}
}
I hope somebody who is aware of java and iOS will come and have a look