I am playing with CocoaAsyncSocket in Swift to bind to a UDP socket and receive messages over the local network.
I am initialising a socket, and trying to bind to a port but am getting a NSPOSIXErrorDomain
error. Perhaps indicating some sort of permissions issue?
My code:
import Cocoa
import CocoaAsyncSocket
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, GCDAsyncUdpSocketDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
let socket = GCDAsyncUdpSocket.init(delegate: self, delegateQueue: DispatchQueue.main)
do {
try socket.bind(toPort: 53401)
} catch let msg {
NSLog("Error....\(msg)")
}
}
}
Full error:
Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted" UserInfo={NSLocalizedDescription=Operation not permitted, NSLocalizedFailureReason=Error in bind() function}
UdpEchoServer
sample app supplied with the project, the same bind call works correctly. – Leveloff