现在IOS UDP通信代码如下
var message = NSData(bytes: send_buf , length: frame_len)
socket = GCDAsyncUdpSocket(delegate: self, delegateQueue: dispatch_get_main_queue())
socket.sendData(message, toHost: address, port: port, withTimeout: 10000, tag: 0)
do {
// try socket.enableBroadcast(true)
try socket.beginReceiving()
} catch {
print(error)
}
打印到的错误如下
Error Domain=GCDAsyncUdpSocketErrorDomain Code=1 "Must bind socket before you can receive data. You can do this explicitly via bind, or implicitly via connect or by sending data." UserInfo={NSLocalizedDescription=Must bind socket before you can receive data. You can do this explicitly via bind, or implicitly via connect or by sending data.}