Joky

Joky

V2EX member #167347, joined on 2016-04-08 23:55:38 +08:00
Per Joky's settings, the topics list is hidden
Deals info, including closed deals, is not hidden
Joky's recent replies
```swift
import Foundation
import CocoaAsyncSocket

class WakeOnLan: NSObject, GCDAsyncUdpSocketDelegate {
var udpSocket: GCDAsyncUdpSocket!

override init() {
super.init()
udpSocket = GCDAsyncUdpSocket(delegate: self, delegateQueue: DispatchQueue.main)
}

func wakeup(macStr: String, ipStr: String, port: UInt16) {
let macBytes = macStr.split(separator: ":").compactMap { UInt8($0, radix: 16) }
guard macBytes.count == 6 else { return }

var packet = Data(repeating: 0xFF, count: 6)
for _ in 0..<16 {
packet.append(contentsOf: macBytes)
}

do {
try udpSocket.enableBroadcast(true)
udpSocket.send(packet, toHost: ipStr, port: port, withTimeout: -1, tag: 0)
} catch {
print("发送数据包时出现了问题: \(error)")
}
}

// GCDAsyncUdpSocketDelegate methods
func udpSocket(_ sock: GCDAsyncUdpSocket, didSendDataWithTag tag: Int) {
print("数据包发送成功")
sock.close() // 发送完毕后关闭套接字
}

func udpSocket(_ sock: GCDAsyncUdpSocket, didNotSendDataWithTag tag: Int, dueToError error: Error?) {
if let error = error {
print("未能发送数据包, 错误: \(error)")
}
sock.close() // 如果发送失败,也关闭套接字
}

func udpSocketDidClose(_ sock: GCDAsyncUdpSocket, withError error: Error?) {
if let error = error {
print("UDP socket 已关闭, 错误: \(error)")
} else {
print("UDP socket 已正常关闭")
}
}
}

// 使用
let wol = WakeOnLan()
wol.wakeup(macStr: "00:30:64:69:F8:A7", ipStr: "192.168.100.255", port: 9)
```
May 24, 2016
Replied to a topic by Joky 求职 [北京][iOS 求职]低端码畜,求一份 iOS 工作
@mrsolo 谢谢您,学过化工才知道,搞化工的难处,也挺后悔转行太晚了,如果大学早些转,现在也不会是这样子,加油
May 23, 2016
Replied to a topic by Joky 求职 [北京][iOS 求职]低端码畜,求一份 iOS 工作
@sivacohan 排水也挺辛苦的,共勉
May 23, 2016
Replied to a topic by Joky 求职 [北京][iOS 求职]低端码畜,求一份 iOS 工作
@queuey 现在着手在写一个 App ,边写边找,想上架之后应该机会能多一点优势
May 23, 2016
Replied to a topic by Joky 求职 [北京][iOS 求职]低端码畜,求一份 iOS 工作
@vwok 谢谢您
May 23, 2016
Replied to a topic by Joky 求职 [北京][iOS 求职]低端码畜,求一份 iOS 工作
@jackisnotspirate 好的,谢谢您的建议,我想试着走一段
May 23, 2016
Replied to a topic by Joky 求职 [北京][iOS 求职]低端码畜,求一份 iOS 工作
@nathanw 谢谢您,我会考虑的
May 23, 2016
Replied to a topic by Joky 求职 [北京][iOS 求职]低端码畜,求一份 iOS 工作
@TomorJM 谢谢您的建议,我正在着手做些东西
May 23, 2016
Replied to a topic by Joky 求职 [北京][iOS 求职]低端码畜,求一份 iOS 工作
@paradoxs 我是自己工作攒下的钱来培训的,毕业后没跟家里伸手了
May 23, 2016
Replied to a topic by Joky 求职 [北京][iOS 求职]低端码畜,求一份 iOS 工作
@paradoxs 您可能没注意看,我在文的最后写了,他们要求写 2~3 年工作经验,但是我不想伪造假简历,想用真实简历找一份能踏实做下来的工作
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1070 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 14ms · UTC 18:27 · PVG 02:27 · LAX 11:27 · JFK 14:27
♥ Do have faith in what you're doing.